my dog learned polymorphism
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

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Is it legal to override a static method?

By failing to prepare, you are preparing to fail.
Benjamin Franklin (1706 - 1790)

By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
Even though you can have the same static method in the subclass as the super class, it's not actually overidding. i.e. you can not call super.superclassmethod() from the subclass.


So much trouble in the world -- Bob Marley
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Static methods aren't overridden they're hidden. If you have a static method with the same signature in a subclass as there is in the super class the subclass method will hide the superclass method. In other words static methods behave like variables and are subject to early binding not runtime.
Check out this code:

The output is:
super class method
sub class method
super class method
You can see that the last method call, if the method were overridden, would have called the subclass method.
hope that helps

Sun Certified Programmer for the Java� 2 Platform

I agree. Here's the link:
subject: Static methods
jQuery in Action, 3rd edition