The moose likes Beginning Java and the fly likes static methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "static methods" Watch "static methods" New topic

static methods

Suri Babs
Ranch Hand

Joined: Mar 27, 2003
Posts: 50
Can i override static methods (y/n). Explanation please in either case.
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

You can override static methods. Look at the following code:

The thing is, static methods do not participate in polymorphism. Note that when you declare:

it prints "Super," even though the instance is of type "Sub"

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
You can not override static methods. Static methods are hidden not overridden.
JLS If a class declares a static method, then the declaration of that method is said to hide any and all methods with the same signature in the superclasses and superinterfaces of the class that would otherwise be accessible to code in the class. A compile-time error occurs if a static method hides an instance method.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
I agree. Here's the link:
subject: static methods
It's not a secret anymore!