aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding doubt??" Watch "Overriding doubt??" New topic
Author

Overriding doubt??

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9427
    
    2

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
Greenhorn

Joined: Dec 10, 2006
Posts: 3
Hi,
please read this, it may be solve your doubt

http://faq.javaranch.com/view?OverridingVsHiding
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. 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

Joined: Sep 26, 2006
Posts: 9427
    
    2

Thanks for the effort.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Overriding doubt??