Constructor chaining is the process of calling one constructor from another constructor with respect to current object. One of the main use of constructor chaining is to avoid duplicate codes while having multiple constructor.
reference id;
Example:(super class)
class TechPark{
final static String COURSE =”JAVA”;
/* public TechPark()
{
System.out.println(“parent def cons”);
}*/
public TechPark(int a){
System.out.println(“parent param cons”);
}
void feeStructure(){
System.out.println(19500);
}
}
subclass;
class VTechPark extends TechPark{
// @Override
void feesStructure(){
System.out.println(1);
}
public VTechPark(){
super(7);
System.out.println(“child def constructor”);
}
public static void main(String[] args){
VTechPark vt=new VTechPark();
//tp.feeStructure();
}
}
example:
parent param cons
child def constructor