• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

A small doubt while calling overriden method

 
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 ]
 
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 ]
    Bookmark Topic Watch Topic
  • New Topic