It's not a secret anymore!
The moose likes Beginning Java and the fly likes inheriting a static method..... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "inheriting a static method....." Watch "inheriting a static method....." New topic

inheriting a static method.....

rahul mehra
Ranch Hand

Joined: Aug 20, 2007
Posts: 33
why can't a instance method in the subclass override a static method of the superclass??? why do we get a complie time error???

marc weber

Joined: Aug 31, 2004
Posts: 11343

See if this helps: Overriding vs. Hiding.

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
jaspreet atwal
Ranch Hand

Joined: Sep 05, 2007
Posts: 52
who decided to make java so confusing??

Still Learing..
Adam Schaible
Ranch Hand

Joined: Oct 04, 2007
Posts: 101
It will make sense later for you..

Statics do not have context - by context, usually we perform behaviors on an object, ie:

In this example, d (Dog object) is the context. Since statics don't have context, the only way we are supposed to reference them is by the class - so for example:

Since I'm not actually creating an instance of service, how exactly would I override it?

Two different methods, get what I'm saying?
[ November 06, 2007: Message edited by: Adam Schaible ]
I agree. Here's the link:
subject: inheriting a static method.....
It's not a secret anymore!