• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A small doubt while calling overriden method

 
Neha Mohit
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator



o/p :-

Inside Foo Constructor
Inside Bar Show
Inside Bar Constructor


My doubt is why is it calling method of Bar class , when i do this.show() rather show() of Foo Class in Foo constructor the Bar object is still not completely created. But it seems polymorphism is not depended up on object creation.


Please explain the above behaviour , Thanks in advance
[ March 03, 2008: Message edited by: Neha Mohit ]
 
jim xu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since the object created is Bar's object, so "this" should reference to the Bar's object. And because the method is overridden, Bar object has no visibility of Foo's show. Try change the signature of the method for foo and call it from Bar's object, you will see that it actually calls Foo's show again, in that case these two shows become just two different methods (happened to have the same name) Interesting enough is that changing the access level can also change the calling sequence.

[ March 04, 2008: Message edited by: jim xu ]
[ March 04, 2008: Message edited by: jim xu ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic