• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

static with abstract

 
Angela lewis
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • 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.
 
Swamy Nathan
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • 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.
 
Sundar Murthi
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • 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.
 
Sanyev Babu
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
  • 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.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic