Can a constructor be static or final or synchronized?

What is a constructor, and what is its purpose?
A Constructor is special method and must have same name as Class.
A Constructor is invoked to initialize an object.
A Constructor does not syntactically return any value. But implicitly returns an instance of the object it initializes.

If Class does not have any constructor, Compiler generates an Implicit constructor.
Constructor(s) which is explicitly added by developer are called Explicit constructors.

Constructor with no arguments is called Default Constructor.
Constructors with parameters is called Parameterized Constructors.

Having multiple constructors with different number or different types of parameters is called Constructor Overloading

Access Specifier which can be used with Constructor

Constructor can be declared as private, public, protected or default or none

static or final or synchronized keywords can never be used with a Constructor

How to invoke a constructor, from another constructor of same class?
A Constructor of a class can be invoked from another Constructor of same class, by using this(); statement

How to explicitly invoke a Base class constructor, from Derived class constructor?
In Inheritance, it is possible to invoke constructor of immediate Base class from a Derived class constructor, by using super(); statement

What is Copy Constructor?
A Copy constructor creates an object with same state as the object which is sent as parameter to Copy Constructor. Type of parameter accepted by Copy Constructor is same as that class Type.

Below is an example of Copy constructor.

class Rect{

    private double width, height;

    // A normal parametrized constructor
    public Rect(double width, double height) {
        this.width = width;
        this.height = height;

    // copy constructor
    Rect(Rectc) {
        System.out.println("Copy constructor called");
        width  = c.width ;
        height = c.height;

public class CopyConstructorDemo {

    public static void main(String[] args) {
    Rect c1 = new Rect(10, 15);

    // Following involves a copy constructor call
    Rect c2 = new Rect(c1);

    System.out.println(c2); // toString() is called here

Is constructor invoked when an object is cloned?

Answer is yes and no. And that depends on implementation of clone( ) method in the class which implements Cloneable interface.

What is singleton?

Singleton ensures that only zero or at most one object of a class can exist.

Can both statements be used from a single constructor?


You may also like to read:
How to invoke constructor, using this
How to invoke base constructor
What is singleton?

What is Singleton Design Pattern

Singleton Design Pattern ensures that maximum one object can exist for a class. Below are steps you need to make a class Singleton.

1. Make all constructors private.
2. Add a static method, which creates and returns object of the class.
3. Add a static data member of its type, so that it can be returned, if object already exists.
4. Add a static int data member, which stores number of objects currently exists(whose value will be either 0 or 1, always)
5. In static method(added above in step 2), if number of objects is zero, create new object(by invoking private constructor), and return it. If number of objects is one, return existing object, without creating new object.

Below is example Design pattern code.
public class Abc {

private static int objCount = 0;

//step 3
private static Abc obj;

//step 1
private Abc(){ System.out.println(“This is Constructor”);}

//step 2
public static Abc createInstance(){
if(objCount ==0)
obj= new Abc();
System.out.println(“object created”);
System.out.println(“Returning existing object”);

return obj;


public class MySingleton {
public static void main(String[] args) {

Abc nc = Abc.createInstance();
Abc nc1 = Abc.createInstance();
Abc nc2 = Abc.createInstance();

object created
Returning existing object
Returning existing object