This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan 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 Android Security Essentials Live Lessons this week in the Android 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: 9345
    
    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: 9345
    
    2

Thanks for the effort.
 
Don't get me started about those stupid light bulbs.
 
subject: Overriding doubt??
 
Similar Threads
Overriding static methods
Statics
OO, method calls in compile time
Regarding static
Static methods and inheritance.