Reputation: 57
So let's say ClassB
is a class defined inside ClassA
(Nested Classes), my question is, if ClassB
is declared abstract
as it contains abstract Methods, would ClassA also have to be declared Abstract
?
Upvotes: 1
Views: 197
Reputation: 44398
Nope, it doesn't. It doesn't matter whether the outer or parent class is abstract
, there is no rule in Java enforcing a class being abstract
.
An example:
class classA {
abstract class classB { // can also be static
abstract void foo();
}
}
On the other hand, it's a bit different with the methods: abstract
methods must be placed only inside the abstract
classes or interfaces (implicitely abstract).
Upvotes: 1
Reputation: 180286
No. The methods of each class are its own. A class does not own the methods of other classes (or interfaces!) nested within, and containing a nested abstract class or a nested interface does not require the container class to be abstract.
Upvotes: 1