
how to override toString method to display integer

class Point {
private int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public String toString() {
return "X=" + x + " " + "Y=" + y;
}
}
public class ToString {
public static void main(String args[]) {
Point point = new Point(10, 10);
System.out.println(point);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.