Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why static methods can not be overridden

 
teja dharma
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why static methods can not be overridden ?
 
Himalay Majumdar
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because the belong to class..not Object
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15484
43
Android IntelliJ IDE Java Scala Spring
 
Guilherme Bazilio
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 826
Chrome Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Guilherme Bazilio
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sudipo shekhar wrote:
I think it is known as hiding


I think hiding is also a valid name. K&B book calls redefine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic