Forum

Number Of Page View:100,000+/Months
LOGIN |New User

Reply

What is constructor chaining and how to do this in Java?

Contructor can be overloaded,i.e. a single class can hava more than one contructor. A construct may call to another constructor. The first statement in the constructor must be a call to either this() or  super() but not both. The super() will call the matching superclass constructor according to the number of arguments passed in the super(). A this() will call the overloaded constuctor in the same class according to the parameter list. The called constructor may also make a call to the other constructor using this(). This type of contructor calling in the same class is called constructor chaining.