This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 3019
    
  35

"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
What would SCJP exam questions look like? -- Home -- Twitter -- How to Ask a Question
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2996
    
    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: 3019
    
  35

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: 38033
    
  22
Welcome to the Ranch Masa Saito.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: why can't abstract class have abstract static method?
 
Similar Threads
abstract static method
Abstract Class
static method inside a abstract class?
abstract method
How to user polymophism??