File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Overriding" Watch "Overriding" New topic


sandhi mridul
Ranch Hand

Joined: Jan 25, 2008
Posts: 71
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?

Sergio Calvo

Joined: Feb 22, 2008
Posts: 8
See here:
Chethan C Gowda

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.

I agree. Here's the link:
subject: Overriding
It's not a secret anymore!