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

static problem

 
geet kaur
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why can't we declare abstract methods as static...?i know that we can't ...but don't know the exact reason for it...please help!
 
Henry Wong
author
Marshal
Pie
Posts: 21514
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static methods can't be overriden, so it really doesn't make sense to declare a static method as abstract, as there is no way to define it by subclassing.

Henry
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, in short, because in Java, abstract method implementations are looked up at runtime by checking the exact type of the object the method is called on. Since static methods are called without reference to an object -- i.e., you can call them as ClassName.methodName(), with no object involved -- there would be no way to figure out which implementation you mean. Of course you could work out a system for doing this, but Java's creators wanted the language to stay simple, with relatively few rules for understanding its behavior.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic