It is not possible to create an object by directly calling the constructor of an abstract
class. The constructor of an abstract
class can be called only from a derived class. It therefore seems to me that constructors of an abstract class must be either protected
or package-private (the latter for the unusual cases of restricting use of a constructor to derived classes within the package). Yet Java allows the constructor of an abstract
class to be public
.
Are there any circumstances in which it is useful to declare the constructor of an abstract
class to be public
, rather than protected
or package-private?
This is not quite a duplicate of the question "Abstract class constructor access modifier": clearly you can declare a constructor to be public
; I want to know whether there is ever any good reason to do so. It seems to me that there is not. I see that C# has a similar peculiarity.