I know two ways, which prohibit inheritance:
- make a final class
- announce a private constructor
To prevent the inheritance must the default constructor of the class announces as private.
class Class {
private Class() {}
}
class OtherClass extends Class {
// Error! There is no default constructor available
}
Did everything done for using super
?
class Class {
public Class() {}
}
class OtherClass extends Class {
public OtherClass() { super(); } // Did everything done for this opportunity?
}
I want to know why you can not inherit from a class with private default constructor and what is conditioned by?