This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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 Murach's Java Servlets and JSP this week in the Servlets forum!
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
 
Similar Threads
Code output -Doubt.
Overloading & Overriding!
Certification Study Guide by Simon Roberts Philip Heller Micheal Ernst
Can someone explain the error @ Line-03
Regarding Method Shadowing