File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes static / non-static method overriding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "static / non-static method overriding" Watch "static / non-static method overriding" New topic

static / non-static method overriding

Ryan Deiter

Joined: Mar 13, 2002
Posts: 9
i know you can't override static methods by why can't you override a non-static method with a static method.
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

"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.

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
I agree. Here's the link:
subject: static / non-static method overriding
It's not a secret anymore!