File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Strange "this" behavior

 
Sun LiWei
Ranch Hand
Posts: 49
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

the output is :
method B
Super Class
in class Father,why this() calls the Father's constructor but this.method()A() calls the class Child's methodA()?
 
Vin Kris
Ranch Hand
Posts: 154
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nothing strange here.. polymorphic rule.. RTTI... type of the object is Child... therefore the method from child is invoked.
btw... preferably don't use this style of coding unless the invoked methods are private or final. It could cost a hapless maintenance chap a lot of sleepless nights.
 
pree sree
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Objects always know 'who they are ' on the basis of instanceof operator.
When an object is created the instances of all its super classes are also created.at runtime it is decided which implementation is called.(except for static methods which are resolved at compile time.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic