This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Strange "this" behavior" Watch "Strange "this" behavior" New topic

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 runtime it is decided which implementation is called.(except for static methods which are resolved at compile time.
It is sorta covered in the JavaRanch Style Guide.
subject: Strange "this" behavior
Similar Threads
Regarding Method Shadowing
Code output -Doubt.
Overloading & Overriding!
Certification Study Guide by Simon Roberts Philip Heller Micheal Ernst
Can someone explain the error @ Line-03