• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract

 
Ram Jonnalagadda
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai,
Someboby clarify my doubt.
Can u combine abstract with any other modifiers like private,static in a class or method declarations
thanks
bye
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract methods must be overridden by subclasses to provide implementation. Since private methods are not visible in subclasses abstract methods cannot be private. Similarly, since static methods cannot be overridden, they cannot be static either.
Try out this code and see what the compiler says -

Ajith
 
Ram Jonnalagadda
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hai Ajith Kallambella
Thanks for ur response.
But is it true that Static methods must be overridden to be Static.They can't be overridden to be non static.

Need some response
thanks
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. Static methods cannot be overridden at all.
Here's why - Unlike instance methods which is associated with the objects of a particular class, static methods( and static variables ) are associated with the class itself. So, when a class is subclassed, if the superclass contains static entities( methods/variables ), they are not inherited in the subclass. You can only override something that is inherited and hence static entities cannot be overridden.
What's more, static methods are resolved at compile time and (since they cannot be overridden, ) they do not exhibit polymorphism (aka runtime binding ).
Often people get confused between overriding and redeclaration. Static methods can be redeclared in the subclass and when you do so, the new method shadows or hides the method in the superclass.
Hope that helps,
Ajith
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic