• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

final static methods

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The static methods can not be overriden, i've heard that many times. Static methods belong to classes, not instances, therefore they can be just hidden by a method in the subclass, not overriden. Nevertheless, if a static method is declared final in the superclass, it can not be redeclared in a subclass, this behaviour being equivalent with trying to override the static method within the superclass.

Does anyone have an explanation for this behaviour?
 
Ranch Hand
Posts: 30
Mac OS X Spring AngularJS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static methods aren't overridden, they are 'redefined'. We use the term 'redefined' because polymorphism doesn't occur with overridden static methods.

Don't be distracted because the method is static however. It's the 'final' keyword that is the most important here. Final ensures that a method can't be overridden (or redefined in the case of a static method). Therefore it doesn't matter if the final method is static or not. You just can't override a method of a subclass of which the superclass method is final.
 
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dylan Honorez posted October 18, 2006 07:27 AM

Static methods aren't overridden, they are 'redefined'. We use the term 'redefined' because polymorphism doesn't occur with overridden static methods.



True, but the funny thing is that the compiler says:
Cannot override...



Yours,
Bu.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic