File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Constructor

 
avseq anthoy
Ranch Hand
Posts: 106
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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()".
 
Karel KoboojBot
Ranch Hand
Posts: 35
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic