| 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
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2729
|
|
"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 (Download) - the free mock exam kit for SCJP / OCPJP
HELP me! -- Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
|
 |
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2817
|
|
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
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2729
|
|
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: 32833
|
|
Welcome to the Ranch Masa Saito.
|
 |
 |
|
|
subject: why can't abstract class have abstract static method?
|
|
|