This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

abstract and static

 
Basanti Mathad
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone tell me why can a method not be both abstract and static.
thank you
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because static methods cannot be overridden, that is, they do not exhibit polymorphic behaviour.
An abstract method is meant to be provided an implementation by one overridding method in a subtype of the type where it was declared. The abstract method was born to be overriden.
However a static method already has an implementation that is independent of any instance of its class, and of course, independent of instances of subtypes. The implementation of a static method is bound to the type where it was declared. This is the opposite to polymorphism. The static method was born to be called as it is, without the need to create any instance.
 
Basanti Mathad
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it.
Thank u so much....
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To understand this -- you really need to have a good understanding of some basic OO ideas -- like inheritance and overriding.
When you extend a class, you inherit all of its accessible instance members (accessibility is of course defined by the access modifiers: private, public, protected or the default access level -- no modifier). Notice I said you inherit its instance members -- not the static ones that belong to the class, and not the object.
On the other side you have the modifier abstract -- by definition, if you declare a method as abstract you're saying that this method has to be overridden by the subclass unless of course you declare the subclass as abstract too... and then you've gotta do the whole thing over again with it's subclass -- but that's beside the point.
So -- what we've got so far:
-- a static method will not be inherited when by your subclass.
-- an abstract method MUST be overriden by the subclass.
See how the two conflict? You can't have something defined as static abstract because then you're saying "This thing belongs to the class, not the object, so it won't be inherited when this class is extended; on the other hand -- this method MUST be overridden when this class is extended" -- a total contradiction -- so the compiler won't allow it.
 
Sridhar Srikanthan
Ranch Hand
Posts: 366
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Basanti,
Check the answer here in this link
http://www.artima.com/legacy/design/interfaces/messages/39.html
Good Luck
Sridhar
 
Basanti Mathad
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank u all very much...
I could get the reason why its impossible.
thanks again...
basanti
 
Jose Botella
Ranch Hand
Posts: 2120
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would say that static members are inherited. Though static methods cannot be overridden, but hidden.
From JLS 8.4.6

A class inherits from its direct superclass and direct superinterfaces all the non-private methods (whether abstract or not) of the superclass and superinterfaces that are accessible to code in the class and are neither overridden (�8.4.6.1) nor hidden (�8.4.6.2) by a declaration in the class.

Hidden only applies to static members.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic