• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

abstract and static

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone tell me why can a method not be both abstract and static.
thank you
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got it.
Thank u so much....
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic