| Author |
why, if one method is declared as abstract, the same cannot be declared as static ?
|
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 543
|
|
why, if one method is declared as abstract cannot be declared as static ?
i m talking about interface in which methods are implicitly abstract and that method cannot have static modifier ? why so ?
|
The Only way to learn is ...........do!
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 2686
|
|
|
Marking a method abstract means that you will override it in a sub-class and provide the implementation. A static method cannot be overridden, so it would be impossible to provide the implementation of a static abstract method. So it makes no sense to allow it.
|
 |
naved momin
Ranch Hand
Joined: Jul 03, 2011
Posts: 543
|
|
Matthew Brown wrote:Marking a method abstract means that you will override it in a sub-class and provide the implementation. A static method cannot be overridden, so it would be impossible to provide the implementation of a static abstract method. So it makes no sense to allow it.
static method cannot be overriden because those methods are for that particular class ?
|
 |
Seetharaman Venkatasamy
Bartender
Joined: Jan 28, 2008
Posts: 4503
|
|
naved momin wrote:static method cannot be overriden because those methods are for that particular class ?
Please, SearchFirst
|
 |
Dennis Deems
Ranch Hand
Joined: Mar 12, 2011
Posts: 547
|
|
naved momin wrote:
Matthew Brown wrote:Marking a method abstract means that you will override it in a sub-class and provide the implementation. A static method cannot be overridden, so it would be impossible to provide the implementation of a static abstract method. So it makes no sense to allow it.
static method cannot be overriden because those methods are for that particular class ?
Static members are shared among all instances of a class -- one might say, independently of its instances.
|
 |
Jeff Verdegan
Bartender
Joined: Jan 03, 2004
Posts: 3133
|
|
naved momin wrote:
Matthew Brown wrote:Marking a method abstract means that you will override it in a sub-class and provide the implementation. A static method cannot be overridden, so it would be impossible to provide the implementation of a static abstract method. So it makes no sense to allow it.
static method cannot be overriden because those methods are for that particular class ?
They cannot be overridden because the language designers decided to make it that way. In some languages (like SmallTalk, I think), static methods can be overridden. Java's designers had a different model in mind for class, objects, and polymorphism. It was a language design choice. If you want to know why that choice was made, you'd have to ask them, or see if it shows up in a whitepaper somewhere. A good guess, though, would be that it keeps the language simpler. Simplicity has always been one of Java's key goals.
|
 |
 |
|
|
subject: why, if one method is declared as abstract, the same cannot be declared as static ?
|
|
|