| Author |
Why it is illegal to use abstract and static modifiers together in method declaration ?
|
Nitesh Nandwana
Ranch Hand
Joined: Jun 07, 2011
Posts: 115
|
|
I want to know about this that why it is illegal. i don't think it is a crime to use both together, please satisfied me with solid reason .
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3044
|
|
|
How would you implement such an abstract method? Surely not in a subclass, because static methods aren't inherited.
|
 |
Nitesh Nandwana
Ranch Hand
Joined: Jun 07, 2011
Posts: 115
|
|
Stephan van Hulst wrote: because static methods aren't inherited.
Sorry but i did it as you can see below .It is really very easy to inherit static method.Is it not ?
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3786
|
|
|
But they can't be overridden, which is the important thing. An abstract method is "overidden" when the implementation is provided, but that's not possible with a static method.
|
 |
Nitesh Nandwana
Ranch Hand
Joined: Jun 07, 2011
Posts: 115
|
|
Matthew Brown wrote:But they can't be overridden, which is the important thing. An abstract method is "overidden" when the implementation is provided, but that's not possible with a static method.
hahaha again nice answer but i can override static method you want see ?
|
 |
Nitesh Nandwana
Ranch Hand
Joined: Jun 07, 2011
Posts: 115
|
|
Matthew Brown wrote:But they can't be overridden
Static method inheritance and overridden is given below dear for only you
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3786
|
|
|
That's not overriding. That's hiding. When you call with a StaticTest1 reference you get the StaticTest1 method. When you call with a StaticTest2 reference you get the StaticTest2 method. What you don't get is run-time polymorphism, which is what true overriding would imply.
|
 |
Nitesh Nandwana
Ranch Hand
Joined: Jun 07, 2011
Posts: 115
|
|
Matthew Brown wrote:That's not overriding. That's hiding. When you call with a StaticTest1 reference you get the StaticTest1 method. When you call with a StaticTest2 reference you get the StaticTest2 method. What you don't get is run-time polymorphism, which is what true overriding would imply.
nice i was totally wrong sorry for that
|
 |
Nitesh Nandwana
Ranch Hand
Joined: Jun 07, 2011
Posts: 115
|
|
http://www.coderanch.com/how-to/java/OverridingVsHiding
If you run this, the output is
instanceMethod() in Bar
classMethod() in Foo
|
 |
 |
|
|
subject: Why it is illegal to use abstract and static modifiers together in method declaration ?
|
|
|