Constructor Chaining in Java
Wednesday, 30 April 2008
When you have a class that extends another class in Java, initializing that child class will first call the parent’s initializer, and then the child’s. So if you have:
public class Base {
public Base() {
System.out.print("Base ");
}
}
public class Derived extends Base {
public Derived() {
System.out.print("Derived");
}
}
The code Derived d1 = new Derived(); will print Base Derived
.