class A { A(int x) { System.out.println("Parent constructor"); } } class B extends A { B(int x) { System.out.println("child constructor"); } } public class Main { public static void main(String args[]) { B ob =new B(10); } }
Error
Note:
Constructors can not inherit to one class to another class.
To overcome this problem super() is introduced;
class A { A(int x) { System.out.println("Parent constructor"); } } class B extends A { B(int x) { super(10); System.out.println("child constructor"); } } public class Main { public static void main(String args[]) { B ob =new B(10); } }
Parent constructor
child constructor