The moose likes OO, Patterns, UML and Refactoring and the fly likes questions about method overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Engineering » OO, Patterns, UML and Refactoring
Reply Bookmark "questions about method overriding" Watch "questions about method overriding" New topic
Author

questions about method overriding

Chrix Wu
Ranch Hand

Joined: Nov 15, 2009
Posts: 121
Say I have Class A as super class, and it has method "caller()" which uses "callee()"

Then I have Class B inherits from A, and now I rewrites "callee()", and in the drived class version of "caller()", simple calls "super.caller()"

When Object B's caller() is invoked, is the new version of callee() going to be invoked too?

[Thumb - QQ截图20110922094459.png]
 Filename QQ截图20110922094459.png [Disk] Download
 Description
 Filesize 3 Kbytes
 Downloaded:  5 time(s)


** SCJP 5.0 84% **
** SCWCD 1.5 76% **
Sean Keane
Ranch Hand

Joined: Nov 03, 2010
Posts: 581

Chrix Wu wrote:When Object B's caller() is invoked, is the new version of callee() going to be invoked too?


I'd suggest you try writing some Java code, compiling it, and running it. Then you will get your answer. Simple


SCJP (1.4 | 5.0), OCJP (6.0), OCMJD
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2207

Sean Keane wrote:
I'd suggest you try writing some Java code, compiling it, and running it. Then you will get your answer. Simple
That is an excellent advice.
The best way to understand what is happening, is to code an example and see what it does.

You could use a debugger and step through your code to follow the methods that are called.
There is no magic involved, and it is fun to learn how the mechanism works that way.
 
 
subject: questions about method overriding
 
Threads others viewed
Object Communication
calling outside methods and returning something...
identifying the super object which invoked a method which was overridden
Who called?
TransactionRequiredException
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com