class ClassA
{
private ClassA()
{
}
}
class ClassB extends ClassA
{
//here we will get a compiler error that cannot extend a class with private constructor
}
public class GenericTestClass
{
private class TestingInnerPrivateClass
{
private TestingInnerPrivateClass()
{
}
public void display()
{
System.out.print("Test");
};
}
public class InnerPublicClass extends TestingInnerPrivateClass
{
//here i am able to extend a private class
}
public static void main(String[] args)
{
GenericTestClass genericTestClass = new GenericTestClass();
GenericTestClass.InnerPublicClass innerPublicClassInstance = genericTestClass.new InnerPublicClass();
innerPublicClassInstance.display();
}
}
If you look at the code above, you can see that I am not able to extend classB
from classA
, but I am able to extend InnerPublicClass
from InnerPrivateClass
.
I am not able to understand how a class which is private and has a private constructor as well is able to be sub-classed when it is an inner class.