When we inherit class into another class then object of base class is initialized first. If a class do not have any constructor then default constructor will be called. But if we have created any parameterized constructor then we have to initialize base class constructor from derived class.

We have to call constructor from another constructor. It is also known as constructor chaining.

When we have to call same class constructor from another constructor then we use this keyword. In addition, when we have to call base class constructor from derived class then we use base keyword.

Example of Base Class Constructor Calling

In the following example we have created Abc is as a base class and inherit it into Pqr. We have created parameterized constructor in class Abc so we have to initialize this constructor from derived class constructor in the following manner:-



		
public class Abc
{
    public int p, q;
    public Abc(int p1, int p2)
    {
        p = p1;
        q = p2;
    }
    public int sum(int x, int y)
    {
        return (x + y);
    }
    
}

//derived class/ child class
public class Pqr : Abc
{
    public int a;
    public Pqr(int a1,int p1, int p2):base(p1,p2)
    {
        a = a1;
    }
    public int sub(int x, int y)
    {
        return (x - y);
    }
}


When we create the object of Pqr class then first it will call Pqr class constructor but Pqr class constructor first initialize the base class constructor then Pqr constructor will be initialized. It is very important point to note down the base class constructor initialized first.