jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Static modifier : Overriding & Hiding 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 "Static modifier : Overriding & Hiding" Watch "Static modifier : Overriding & Hiding" New topic

Static modifier : Overriding & Hiding

Sadhi Mushrif

Joined: May 09, 2003
Posts: 11
Can anyone explain to me the effect of a method of having a static modifier and it's effect while overrriding.
1.If both the overriding and overridden methods have a static modifier.
2.Only if one the 2 methods have a static modifier.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Static methods can not be overridden, they can only be hidden.
If the method in the parent is static then the method in the child must be static. If the method in the parent is not static then the child method can not be static.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
A static method of a subclass can hide a static method with the same name and parameter list in the super class, but a static method can not override a superclass method.
If a reference of the superclass type invokes a static method on an object of a subclass type, then the method of the superclass type is actually used--the method of the subclass is not. That's because a static method is a class method and is not bound to a particular instance of an object. Therefore, the actual type of the instance does not make any difference.
In response to your second question, the result would be a compiler error.

Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
I agree. Here's the link: http://aspose.com/file-tools
subject: Static modifier : Overriding & Hiding
It's not a secret anymore!