class Super
{
private Super ( )
{
System.out.println ( " We are in the super class " );
}
}
class Sub extends Super // ( 1 )
{
Sub ( )
{ // ( 2 )
System.out.println ( " We are in the sub class " );
}
}
public class InextensibleClasses
{
public static void main (
String args[] )
{
Sub objS = new Sub ( ) ; // ( 3 )
}
}
as we can see from line ( 1 ) , that the subclass can extend the super class, but the problem will arrive when we try to create an instance of the sub class at ( 3 ) , while creating the instance a call to the sub class constructor is made which results in a implicit call to the super class constructor at ( 2 ) , now since the super class constructor is private it is not accessible to the subclass , as a result of which we get a compile time error
Thus the subclass was'nt able to extend the super class with a private constructor
regards,
Bhavesh