Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Abstract class

 
sujay kulkarni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can we declare abstract private method in abstract class? static method in abstract class ?
 
Matthew Brown
Bartender
Posts: 4567
8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried to compile it? That will tell you if it's possible or not.
 
sujay kulkarni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
abstract method can't be static giving compile time error
 
Matthew Brown
Bartender
Posts: 4567
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so you know they aren't allowed. Here's why. An abstract method basically says "a subclass will provide the implementation". In effect the subclass is overriding the method, but what it's overriding is the lack of implementation.

Private methods cannot be overridden, because they are not visible to the subclass. So you can't have an abstract private method - it's impossible for a subclass to provide an implementation for it. Similarly, static methods cannot be overridden, and so it doesn't make sense for them to be abstract.

The bottom line is, if a method can't be overridden by a subclass, it can't be made abstract.
 
sujay kulkarni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Matthew for nice explanation.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic