Java / Constructor
Can the class with private constructor be extended?
No, in case of outer classes.
The below program will generate compile time error.
package org.javatutorials.accessModifer.protectedPackage;
class ClassWithPrivateConstructor { private ClassWithPrivateConstructor() { System.out.println("Hello from ClassWithPrivateConstructor"); } } public class ExtendingClass extends ClassWithPrivateConstructor { public ExtendingClass() { System.out.println("Hello from ExtendingClass"); } public static void main(String args[]) { new ExtendingClass(); } }
More Related questions...