This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to call parent class methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to call parent class methods" Watch "How to call parent class methods" New topic
Author

How to call parent class methods

Nilesh Srivastava
Ranch Hand

Joined: Aug 29, 2003
Posts: 70
Hi..
Suppose there are four classes A, B extends A, C extends B and D extends D.
Now if I want to call A's method from D, will super.methCall() do?
or how to call the method.
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
If you do "super.methCall()" from class "D", the JVM will try and resolve it by first looking in class "C", then in class "B", and finally in class "A". It will call "A"-s version only if neither "B" nor "C" has over-ridden it.
If either "B" or "C" has overridden "methCall", there is no way to explicitly invoke "A"-s version from within "D".
[ October 17, 2003: Message edited by: Wayne L Johnson ]
 
Don't get me started about those stupid light bulbs.
 
subject: How to call parent class methods
 
Similar Threads
Question on constructor
instance access
A question about sibling class
Overridding or overloading?
Inner class