Im trying to write a short code which will display the coordinates of the inputted two values into a constructor and when I call the object, it should print the inputted values as, for example, (x,y) if the input is (x,y).
Here is my code so far:
public class DisplayCoordinates {
private int x, y;
public DisplayCoordinates(int x, int y) {
this.x = x;
this.y = y;
}
}
When I call it using the following code, I get DisplayCoordinates@2c7b84de
instead of (14,9)
.
DisplayCoordinates a = new DisplayCoordinates(14, 9);
System.out.println(a);
Can someone help me out please? I am relatively new to Java, so I'm sorry if this is a relatively easy fix. Thank you for your help!