Java / Constructor
Can the inner class with private constructor be extended?
Yes.
package org.javatutorials.accessModifer.protectedPackage; public class PrivateConstructorInnerClass { class Parent { private Parent() { System.out.println("Hello from Parent"); } } class Child extends Parent { public Child() { System.out.println("Hello from Child"); } } public static void main(String[] str) { PrivateConstructorInnerClass pc = new PrivateConstructorInnerClass(); pc.new Child(); } }
Output:
Hello from Parent
Hello from Child
More Related questions...