override static

Is it possible to override a static method ? if so, how?if not why?
[81 byte] By [padikkathavana] at [2007-11-27 2:42:09]
# 1
> Is it possible to override a static method ? if so,> how?No. > if not why?Because it belongs to the class and not to an object.Kaj
kajbja at 2007-7-12 3:06:32 > top of Java-index,Java Essentials,New To Java...
# 2
static methods cannot be overridden but you can overload.
AnanSmritia at 2007-7-12 3:06:32 > top of Java-index,Java Essentials,New To Java...
# 3

> Is it possible to override a static method ? if so,

> how? if not why?

The question of what you can do in Java is determined by the Java Language Specification.

The question of how the JLS came up with its decision is explained in The Java Programming Language by Gosling and others. This is where you find explained why Java is this the way it is. Get this book if you're a serious student of Java.

AnanSmritia at 2007-7-12 3:06:32 > top of Java-index,Java Essentials,New To Java...
# 4

friends ...

you have mentioned so far, that we can not override a static method.

but in java tutorials,http://java.sun.com/docs/books/tutorial/java/IandI/override.html

they have mentioned we can override a superclass static method. but they call it as method hiding.

pls. clarify....

padikkathavana at 2007-7-12 3:06:32 > top of Java-index,Java Essentials,New To Java...
# 5
Hiding is not the same as overriding. Try reading that section and maybe you will understand it.
CaptainMorgan08a at 2007-7-12 3:06:32 > top of Java-index,Java Essentials,New To Java...
# 6

> tutorials,http://java.sun.com/docs/books/tutorial/java

> /IandI/override.html

> they have mentioned we can override a superclass

> static method.

No, they don't mention that at all. What they do mention is that "defining a class method with the same signature as a class method in the superclass" is overriding for instance methods, and hiding for class methods.

They go on to explain the difference. The part after "The distinction between hiding and overriding has important implications."

Lokoa at 2007-7-12 3:06:32 > top of Java-index,Java Essentials,New To Java...
# 7

> they have mentioned we can override a superclass static method. but they call it as

> method hiding.

No - in the section "Class Methods" they describe "a class method with the same signature as a class method in the superclass" as hiding. They go on to note "The distinction between hiding and overriding has important implications." (emphasis added), then go on to detail the distinctions.

pbrockway2a at 2007-7-12 3:06:32 > top of Java-index,Java Essentials,New To Java...
# 8

The version of the overridden method that gets invoked is the one in the subclass. The version of the hidden method that gets invoked depends on whether it is invoked from the superclass or the subclass....

==========

the above is from the java tutorials.

can anyone pls. explain this..

padikkathavana at 2007-7-12 3:06:32 > top of Java-index,Java Essentials,New To Java...