Correct Answer: D
Explanation/Reference:
Explanation: Implementing toString method in java is done by overriding the Object's toString method. The
java toString() method is used when we need a string representation of an object. It is defined in Object
class. This method can be overridden to customize the String representation of the Object.
Note:
Below is an example shown of Overriding the default Object toString() method. The toString() method must
be descriptive and should generally cover all the contents of the object.
class PointCoordinates {
private int x, y;
public PointCoordinates(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
// Custom toString() Method.
public String toString() {
return "X=" + x + " " + "Y=" + y;
}}