Can you call a constructor within a constructor?

Answer Posted / ranganathkini

Yes once constructor can call another constructor by using
the this() statement. Example:

class Account {
private double balance;

// 1st Constructor
public Account( double initBalance ) {
balance = initBalance;
}

// 2nd Constructor
public Account() {
this( 0.0 ); // call the 1st constructor
}
}

Is This Answer Correct ?    8 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters?

587


What are assembly attributes?

549


How would you convert bytes to string?

565


Is linkedlist thread safe in java?

563


What is ctrl m character?

518






What is the use of math abs in java?

552


What is return null in java?

514


Why heap memory is called heap?

589


How do you remove spaces in java?

541


Why pass by reference is not possible in java?

501


what are different ways in which a thread can enter the waiting state? : Java thread

496


Explain the difference between throw and throws in java?

552


Can we assign integer value to char in java?

512


Explain about varargs in java?

585


What do you understand by a Static Variable?

634