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 ]
posted 8 years ago
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 ]