Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static and instance methods

 
rani bedi
Ranch Hand
Posts: 358
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic