This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overriding doubt??

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

Consider the following code,


Guys I'm confused with the code above as how the static method in the parent calss gets called even if the object is of type child??
 
Anbarasu Ganesan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
please read this, it may be solve your doubt

http://faq.javaranch.com/view?OverridingVsHiding
 
ashni Prakash
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static method is a class method.When you are calling callMe() method which is of Parent class from the child class object,the get1() method call will be referred to the class which it resides in,i.e. Parent.java. Thats why the statement"From parent get1()" will be printed.

If you override callMe() method in the child class you get output as" From child get1()" which you are expecting.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the effort.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic