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

What do you understand by synchronization?

578


Write a java program to count the number of words present in a string?

525


Why are there no global variables in java?

570


Can a private method of a superclass be declared within a subclass?

521


What is a void in java?

566






What is the java project architecture?

1771


What are the different types of constructor?

510


Can a singleton class be inherited?

510


What is qualitative variable?

510


Why is java so popular?

617


Using callable statement how can you pass out parameters, explain with example?

572


What is the difference between keyword and identifier?

518


What is == mean?

539


Can classes declared using the abstract keyword cab be instantiated?

550


Does java vector allow null?

526