This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

calling super class methods

kau kau

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()");
public class C extends P
public void m1()
System.out.println("In C.m1()");

public void m2()
System.out.println("In C.m2()");
public static void main(String[] args)
C c = new C();
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 ]

Dirk Schreckmann

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:
subject: calling super class methods
Similar Threads
Method Invocation
Protected Trouble
Instance Variables in Polymorphism
calling superclass methods..
Keyword "this" question