Inheritance And Constructors In Java
Chapter:
Inheritance
Last Updated:
20-07-2016 03:19:17 UTC
Program:
/* ............... START ............... */
class Base {
Base() {
System.out.println("Base Class Constructor Called ");
}
}
class Derived extends Base {
Derived() {
System.out.println("Derived Class Constructor Called ");
}
}
public class JavaConstructorInheritance {
public static void main(String[] args) {
Derived d = new Derived();
}
}
/* ............... END ............... */
Output
Base Class Constructor Called
Derived Class Constructor Called
Notes:
-
In Java, constructor of base class with no argument gets automatically called in derived class constructor.
Tags
Inheritance and constructors, Java