This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes static methods and overrides Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static methods and overrides" Watch "static methods and overrides" New topic
Author

static methods and overrides

kambiz shahri
Greenhorn

Joined: Oct 29, 2007
Posts: 3
It is not possible to override an inherited static method...so the Java cert books says. You can only "redefine the method" in a subclass of the superclass that defined the static method.

However when in eclipse i try to "redefine" the inherited static method, it will complain if try to narrow the access modifier.

The certification book is NOT any clearer on the subject.

thanks for the answers in advance.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
[KS]: However when in eclipse i try to "redefine" the inherited static method, it will complain if try to narrow the access modifier.

Yes, that's because the rules for method hiding (what your book calls "redefining") are similar to the rules for overriding. That doesn't mean that static methods can be overridden - it just means that some of the behavior is similar.

I recommend reading Overriding vs. Hiding for more discussion.


"I'm not back." - Bill Harding, Twister
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: static methods and overrides
 
Similar Threads
static methods can't be overridden?
static constructor
Are the rules regarding timing of initialization of final and non-final fields different?
what can static/instance methods override?
Another hiding vs overriding question