aspose file tools*
The moose likes Beginning Java and the fly likes A small doubt while calling overriden method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A small doubt while calling overriden method" Watch "A small doubt while calling overriden method" New topic
Author

A small doubt while calling overriden method

Neha Mohit
Ranch Hand

Joined: Apr 25, 2006
Posts: 87



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

Joined: Nov 18, 2007
Posts: 6
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A small doubt while calling overriden method
 
Similar Threads
Doubt Overriding
Doubt on Pno-:286(K&B) Book(instanceof)
Doubt with constructor overloading
Doubt in Nested Inner Class