This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding doubt?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding doubt??" Watch "Overriding doubt??" New topic

Overriding doubt??

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9999

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??

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
Anbarasu Ganesan

Joined: Dec 10, 2006
Posts: 3
please read this, it may be solve your doubt
ashni Prakash
Ranch Hand

Joined: Dec 05, 2006
Posts: 50
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. 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

Joined: Sep 26, 2006
Posts: 9999

Thanks for the effort.
I agree. Here's the link:
subject: Overriding doubt??
It's not a secret anymore!