Want to write articles/new answer to be published in javapedia.net? Send in your article with your name to javatutorials2016@gmail.com!

Prev Next

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();

❤Cash Back At Stores you Love !!!❤

Earn your $10 reward when you make your first purchase through Ebates by signing up with clicking below button.

Ebates Coupons and Cash Back

More Related questions...

What is a Constructor? Rules for creating a Java constructor. Types of Java constructor. Java Default Constructor. Java parameterized constructor. Advantages of parameterized constructor. What happens when the developer does not implement default constructor? Purpose of default constructor. Constructor Overloading in Java. Copy-Constructor. Difference between constructor and method in Java. What are pass by reference and pass by value? Can constructor perform other tasks instead of initialization? Can a constructor call/invoke a static method? Can a constructor invoke a non-static/instance method? Can abstract class have constructors? What is the access modifier of the Default constructor? Can the class with private constructor be extended? Can the inner class with private constructor be extended? Can you use this() and super() both together in a constructor? Can constructor be synchronized in Java? Is constructor inherited? Can a constructor be final? Can we call the constructor of a class more than once for an object in Java? Is constructor called when cloning in Java? Different ways to create an object in Java. Difference between Class.newInstance() and Constructor.newInstance(). How to Initialize class with Class.forName() that has parameterized constructor? Can you define a method with the same name as the class? What happens when we add a return type to the constructor? Is Constructor definition mandatory? If a class has an explicit constructor, does compiler create default constructor? Can we throw exceptions from a constructor? What are the access modifiers that cannot be applied to a constructor? What is constructor chaining? How do I call subclass constructor from superclass constructor? What is No-arg constructor or default constructor.? Can you declare Constructor as final in Java?
Show more question and Answers...


Comments & Discussions