Java Program for inheritance using constructor


In this program, You will learn how to implement inheritance using a constructor in java.


class A { 
   A(){ 
      //statement
   }
}

class Main extends A { 
  Main(){ 
       //statement
  }
}

Example: How to implement inheritance using constructor in java.

class A {

    A() {
        System.out.println("A constructor is called here");
    }
}

class Main extends A {

    Main() {
        System.out.println("Main constructor is called here");
    }

    public static void main(String args[]) {
        Main obj = new Main();
    }
}

Output:

A constructor is called here
Main constructor is called here