Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt from Khalid Mughal

 
lalit upadheyay
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In the following code :



How is the method call at line 1 in demonstarte() method of NeonLight class different than the method call at the next line ? Though both the methods are available in TubeLight and Light classes, but the first line in demonstrate() invokes method from TubeLight and next line invokes method from Light. Please help.
 
Shivakanth Thyagarajan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The method follows the principle of Overriding ( i,e the getBill method ), it is resolved at run time.

The second method is a static method( i,e printAll( ) ) which gets resolved at compile time therefore the output.

Important Note:
Static methods are resolved at compile time, therefore cannot be overridden .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic