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

static and instance methods

rani bedi
Ranch Hand

Joined: Feb 06, 2001
Posts: 358
The static method declared in class cannot hide the instance method of the same signature declared in its super class.
The instance method declared in class cannot override the static method of the same signature declared in its superclass.
Whats the reason behind it?

Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
1) Static methods are resolved at compile time, instance methods are "late binding" which means that they are not resolved until runtime, and at runtime the JVM decides between the available methods which one is appropriate.
2) Static methods are always invoked without reference to a particular instance, and instance methods are always invoked with reference to a particular instance.
3) Static methods get loaded to the method area at class load time, instance methods get loaded to the method area at the last possible minute before execution.
Since in either case you describe, one of the methods is static, there is no way for late binding to occur, because the static one is not available as a choice anymore (it's already in place). The JVM just can not handle that situation, so instead the compiler handles it by causing a compile time error.

"JavaRanch, where the deer and the Certified play" - David O'Meara
I agree. Here's the link:
subject: static and instance methods
It's not a secret anymore!