jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes calling super class methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

calling super class methods

kau kau
Greenhorn

Joined: Jan 07, 2004
Posts: 4
could anyone help with this...
I'm calling a super class method.Now, i want this method to call other super class methods..instead it calls the subclass method.(all methods in the superclass are overridden in the subclass).
the expected ouput is -
in C.m1
in P.m2
in P.m1
instead it goes in a loop...
in C.m1
in P.m2
in C.m1
in P.m2....
following is the code -
class P
{
public void m1()
{
System.out.println("In P.m1()");
}
public void m2()
{
System.out.println("In P.m2()");
m1();
}
}
public class C extends P
{
public void m1()
{
System.out.println("In C.m1()");
super.m2();
}

public void m2()
{
System.out.println("In C.m2()");
}
public static void main(String[] args)
{
C c = new C();
c.m1();
}
}
Chris Harris
Ranch Hand

Joined: Sep 21, 2003
Posts: 231
This topic has been crossed post and has been answered in "Java in General (intermediate)".
[ added link -ds ]
[ January 08, 2004: Message edited by: Dirk Schreckmann ]

SCJP 1.2, SCWCD, SCBCD
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Thanks for the heads up, Chris.
kau, please don't post the same question in multiple forums. It just makes it difficult to follow a conversation and uses Ranchers' efforts needlessly.
I'm closing this thread.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calling super class methods