aspose file tools*
The moose likes Beginning Java and the fly likes Abstract class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Abstract class" Watch "Abstract class" New topic
Author

Abstract class

sujay kulkarni
Greenhorn

Joined: Oct 04, 2012
Posts: 15
can we declare abstract private method in abstract class? static method in abstract class ?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

What happened when you tried to compile it? That will tell you if it's possible or not.
sujay kulkarni
Greenhorn

Joined: Oct 04, 2012
Posts: 15
abstract method can't be static giving compile time error
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

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

Joined: Oct 04, 2012
Posts: 15
Thanks a lot Matthew for nice explanation.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Abstract class