This example is to show how to use Constructor chain in Java.
Source Code
package com.beginner.examples;
public class ConstructorChainExample {
public ConstructorChainExample(){
System.out.println("Default constructor");
}
public ConstructorChainExample(String str){
this();// call default constructor
System.out.println("Constructor with String object");
}
public static void main(String a[]){
ConstructorChainExample c = new ConstructorChainExample("java");
}
}
Output:
Default constructor
Constructor with String object