• 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

static / non-static method overriding

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i know you can't override static methods by why can't you override a non-static method with a static method.
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"detox33" --
Please review JavaRanch's naming policy and change your screen name accordingly.
When a method is made static, it becomes a property of its enclosing class, rather than a member of the objects instanced from it. This makes it possible to use the method without creating any object at all.
Method overriding favors a different principle. If you have a method in class Parent overridden in class Child, the idea is you could have either a Parent or Child object in memory, referred to by a Parent reference, and still get the correct behavior (i.e., either the original or overridden method code).
Trying to override a method by using a static modifier implies that you want to supress this dynamic binding itself, as well as the behavior of the original method; this isn't allowed.
Now c'mon, Valentin, break out that JLS and give us the Gospel on the subject.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic