File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the blaze result? 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 "what is the blaze result?" Watch "what is the blaze result?" New topic
Author

what is the blaze result?

andy lau
Ranch Hand

Joined: Apr 08, 2002
Posts: 51
a lot of people say that static method can not be overriden ,it is true or false???
Arun Pai
Ranch Hand

Joined: Mar 11, 2002
Posts: 143
Andy,
More generally known as hiding, as it hides the static method in the superclass.Read this from JLSClass Methods JLS
-Arun
Clive Rodrigues
Greenhorn

Joined: Mar 29, 2002
Posts: 7
A static method can be overridden as long as the overriding method is also static.
Quote from The Java Tutorial:
"Also, a subclass cannot override methods that are declared static in the superclass. In other words, a subclass cannot override a class method. A subclass can hide a static method in the superclass by declaring a static method in the subclass with the same signature as the static method in the superclass."
The Java Tutorial
This compiles:

While this doesn't:

[ April 13, 2002: Message edited by: Clive Rodrigues ]
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
Originally posted by Clive Rodrigues:
A static method can be overridden as long as the overriding method is also static.

Clive, that's not quite accurate. The concept of hiding vs overriding for static methods may seem subtle at first, but after a while you really start to understand what the differences mean.
While it's true that you can say "a static method cannot be overriden by an instance method" and vice versus, that does not imply that therefore a static method can override a static method. Static methods, also known as "class methods", belong to the Class itself. Static method calls are never made polymorphically; that's the biggest difference between those and instance methods.
Static methods can only hide static methods in the superclass.
Just remember, you can override instance methods, but static methods are NEVER overriden; they can be hidden, however.


Rob
SCJP 1.4
Clive Rodrigues
Greenhorn

Joined: Mar 29, 2002
Posts: 7
Thanks Rob, I now understand the subtle difference between overriding and hiding. Overriding enables polymorphism while hiding doesn't apply to polymorphism since the methods are static.
[ April 14, 2002: Message edited by: Clive Rodrigues ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the blaze result?