| Author |
why static methods can not be overridden
|
teja dharma
Ranch Hand
Joined: Feb 07, 2009
Posts: 51
|
|
|
why static methods can not be overridden ?
|
SCJP 5
|
 |
Himalay Majumdar
Ranch Hand
Joined: Sep 28, 2008
Posts: 324
|
|
|
Because the belong to class..not Object
|
SCJP 1.6, SCWCD 5.0, SCBCD 5.0 [loading..]
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
|
See this in the FAQ: http://faq.javaranch.com/view?OverridingVsHiding
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
Guilherme Bazilio
Greenhorn
Joined: Mar 02, 2009
Posts: 23
|
|
Static methods cannot be overriden because they belong to the class, not to an instance of that class.
A static method don't need an instance to be accessed.
So, when you think you are overriding a static method, the only thing you are doing is redefining it.
(If I'm wrong just tell me please :P)
|
 |
Ram Prasad
Greenhorn
Joined: Feb 02, 2008
Posts: 9
|
|
Bazilio is correct.
static methods cannot be overridden.
you can define the same static method in different classes and this mechanism is called redefining. The compiler accepts it and doesn't throw any error. But in run time you wont get the expected results of overriding since it is not actually a overriding.
i guess this should clarify your doubt tejahyd
|
 |
sudipto shekhar
Ranch Hand
Joined: Apr 02, 2008
Posts: 813
|
|
Ram Prasad wrote:Bazilio is correct.
static methods cannot be overridden.
you can define the same static method in different classes and this mechanism is called redefining.
I think it is known as hiding
|
Regards, Sud.
SCJP 5 ScjpFAQ JLS
|
 |
Guilherme Bazilio
Greenhorn
Joined: Mar 02, 2009
Posts: 23
|
|
sudipo shekhar wrote:
I think it is known as hiding
I think hiding is also a valid name. K&B book calls redefine.
|
 |
 |
|
|
subject: why static methods can not be overridden
|
|
|