This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor 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 "Constructor" Watch "Constructor" New topic
Author

Constructor

avseq anthoy
Ranch Hand

Joined: Apr 27, 2004
Posts: 106

When Mobile object is created as line 20.Why the Phone constructor invoke Mobile's showDevice() but not itself showDevice() even if I type "this.showDevice()".


My Way,My Pace
Karel KoboojBot
Ranch Hand

Joined: Apr 09, 2004
Posts: 35
Because of dynamic binding. The actual instance method that will be called depends upon the runtime type of the object you are using. Even if you type this. it still will look at the runtime type of the object and use the method of that type.

Be careful, with static elements and instance variables the behaviour is different in these cases. Try it out with a few examples is the best thing to do to get a clear idea on this subject.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Constructor
 
It's not a secret anymore!