Add a constructor to the Point class that accepts another Point as a parameter and initializes the new Point to have the same (x, y) values. Use the keyword 'this' in your solution. Recall that your code is being added to the following class:

public class Point {
int x; int y;
// // your code goes here
}
(You don't need to write the class header or declare the fields; assume that this is already done for you. Just write your constructor's complete code in the mentioned space.)

Respuesta :

Answer:

public Point (Point p) {

     this.x = p.x;

     this.y = p.y;

}

Explanation:

The name of the constructor must be same as the class name, in this case it is Point.

The constructor does not have a return type and takes required parameters, in this case it takes a Point object.

Lastly, we need to initialize the variables, the x and y variables in the class need to be set to the Point p's x and y.