how to call One constructor from another;

Answer Posted / ajay

Hi,

Using super you can invoke constructor which is in parent
class. to invoke constructor which is in the same class we
have to use this. for example:

public class Point {
int m_x;
int m_y;

//============ Constructor
public Point(int x, int y) {
m_x = x;
m_y = y;
}

//============ Parameterless default constructor
public Point() {
this(0, 0); // Calls other constructor.
}
. . .
}

Is This Answer Correct ?    21 Yes 5 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which data type is a class in java?

571


What is a linkedhashmap java?

552


what are Hostile Applets?

1604


Can there be an abstract method without an abstract class?

539


Is an object null?

561






Why Java is not pure Object Oriented language?

642


How do you sort words in java?

536


Can keyword be used as identifier?

547


What is gc()?

579


When the constructor of a class is invoked?

595


Is it possible to override private or static method in java?

544


Implementations of set interface?

564


Can an interface have a constructor?

514


Explain covariant method overriding in java.

542


What does replaceall do in java?

488