aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Why it is illegal to use abstract and static modifiers together in method declaration ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Why it is illegal to use abstract and static modifiers together in method declaration ?" Watch "Why it is illegal to use abstract and static modifiers together in method declaration ?" New topic
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: 3379
    
    9
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: 4240
    
    7

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: 4240
    
    7

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why it is illegal to use abstract and static modifiers together in method declaration ?
 
Similar Threads
Why i should be use Struts with Tiles Framework Together ??
Collection generics method types
Illegal Aliens Can Get Driver's License In Some 15 States In the U.S.?
What should I do
want to know