aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Strange Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Strange "this" behavior" Watch "Strange "this" behavior" New topic
Author

Strange "this" behavior

Sun LiWei
Ranch Hand

Joined: Aug 10, 2002
Posts: 49

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

Joined: Jun 17, 2002
Posts: 154
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

Joined: Jul 27, 2002
Posts: 34
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
 
subject: Strange "this" behavior