• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Static methods - overriding

 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can static methods be overriden ?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, but they can be hidden. Compile and run this...
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See also here.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, I take *wanting to override a method that is static* to be
a sign that the method might be better recast as a non-static method.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jeff Albrechtsen:
By the way, I take *wanting to override a method that is static* to be
a sign that the method might be better recast as a non-static method.

Absolutely.

On the other hand, if this is an academic question, I would just add that you can prevent the "hiding" behavior by making the static method final.
 
Arnb Sen
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for the answers. That was very informative.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic