Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why can't abstract class have abstract static method?

 
Deepak Patil Patil
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why can't abstract class have abstract static method?
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4433
256
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Deepak Patil Patil", please check your private messages regarding an important administrative matter.

Answer for your question is it is because abstract methods cannot be overridden.
This question has nothing to do with Servlets. I'm moving this to BJ forum.
 
Mike Simmons
Ranch Hand
Posts: 3078
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Devaka Cooray wrote:Answer for your question is it is because abstract methods cannot be overridden.
This question has nothing to do with Servlets. I'm moving this to BJ forum.

I think Devaka meant to say that static methods cannot be overridden. (As explained in the link above.) Meanwhile abstract methods must be overridden. Thus, static methods and abstract methods are fundamentally incompatible.

Deepak: to understand this better, think about this: if a method is abstract, and there are two or more classes that override the method, how does the JVM decide at runtime which version of the method should be executed? And how would this work for a static method?
 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4433
256
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:I think Devaka meant to say that static methods cannot be overridden.

Yeah, it is - my mistake
 
Masa Saito
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding abstract static methods (as well as why interfaces can't have static methods), does not it all come down to method binding? Static methods, by design intent, are not to be associated with instances. So, I am betting the fathers of Java decided to go ahead and bind at compile time. As abstract methods have no known implementations at compile-time, there is nothing to bind to. I bet it was just a design decision to disallow "static polymorphism". Those are contradictory adjectives and concepts.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Masa Saito.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic