Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

questions about method overriding

 
Chrix Wu
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

QQ截图20110922094459.png
[Thumbnail for QQ截图20110922094459.png]
 
Sean Keane
Ranch Hand
Posts: 582
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jan Cumps
Bartender
Posts: 2586
11
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic