This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding" Watch "Overriding" New topic
Author

Overriding

sandhi mridul
Ranch Hand

Joined: Jan 25, 2008
Posts: 71
Hi,
there are 2 programs only diffre in the static n non static.


Ans= Base.test()

another code



ans= Child.test()

My question is why the calling method class is getting change means at one place its Base class however at other its child class. What is the reason behind.

please explain me the how the call is going for a static method and nonstatic method?

Thanks
Sandhya
Sergio Calvo
Greenhorn

Joined: Feb 22, 2008
Posts: 8
See here: http://faq.javaranch.com/view?OverridingVsHiding
Chethan C Gowda
Greenhorn

Joined: Dec 06, 2007
Posts: 22
While calling static methods compiler checks for reference type not the obect type.
In example 1 you are calling static method using Base class reference, where as while calling instance method compiler checks for object type.


Thanks,
Chethan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Overriding