aspose file tools*
The moose likes Beginning Java and the fly likes why can't abstract class have abstract static method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why can Watch "why can New topic
Author

why can't abstract class have abstract static method?

Deepak Patil Patil
Greenhorn

Joined: Apr 12, 2008
Posts: 1
why can't abstract class have abstract static method?
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2891
    
  19

"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.


Author of ExamLab ExamLab - a free SCJP / OCPJP exam simulator
My Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2970
    
    9
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
Saloon Keeper

Joined: Jul 29, 2008
Posts: 2891
    
  19

Mike Simmons wrote:I think Devaka meant to say that static methods cannot be overridden.

Yeah, it is - my mistake
Masa Saito
Greenhorn

Joined: Jun 08, 2010
Posts: 14
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

Joined: Oct 13, 2005
Posts: 36599
    
  16
Welcome to the Ranch Masa Saito.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why can't abstract class have abstract static method?
 
Similar Threads
Abstract Class
abstract method
How to user polymophism??
static method inside a abstract class?
abstract static method