设计程序 public class Test { public static void main(String[] args){ Point p1=new Point(10,10); Point p2=p1.copy(); if(p1==p2) System.out.println("======="); if(p1.equals(p2)) System.out.println("++++++"); if(p1.equals(null)) System.out.println("******"); } }使输出结果为++++++
时间: 2023-07-16 21:16:50 浏览: 165
可以这样修改程序:
```
public class Test {
public static void main(String[] args){
Point p1 = new Point(10, 10);
Point p2 = p1.copy();
if(p1 == p2)
System.out.println("=======");
if(p1.equals(p2))
System.out.println("++++++");
if(p1.equals(null))
System.out.println("******");
}
}
class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public Point copy() {
return new Point(this.x, this.y);
}
@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof Point)) {
return false;
}
Point other = (Point) obj;
return this.x == other.x && this.y == other.y;
}
}
```
输出结果为:
```
++++++
```
阅读全文