• 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

static with abstract

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
abstract modifier can't be used with static modifier.
Can someone please tell me the reason for this.
I guess if i know the reason it'll be easier to remember.
 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
abract means a concrete implementation may override it. It also means that if the abstract class is used as a base class and the method when invoked will cause the actual instance's method to be invoked (polymorphism). This of course implies that the method should be an instance method. Hence it cannot be static.
 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I hope Concrete implamentations must define the abstract methods.

my assumption is
Actualy abstract means not fully defined. You can say, a method is Not fully defined then how it is resanable to say it is common to all instances of a class.


i think
the concreate class can able to defined as static
like



but i am not sure.
 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An abstract method means that the method is not implemented. A static method means that the method can be accessed using the class name. It is not tied to any instance of the class. So if we declare a method as abstract then it should not be accessed. If you make that method static it becomes accessible which is not acceptable. (Why should we access a method which is not implemented) So it should result in a compile time error.

Regarding classes a top level class cannot be made static. So there is no question on abstract and static coming together.
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I remember it this way:

1. a static method cannot be overridden.
2. an abstract method must be overridden to give it an implementation.

You can't have both of these, so both static and abstract are not allowed.
 
Looky! I'm being abducted by space aliens! Me and this tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic