-->
当前位置:首页 > 题库 > 正文内容

函数题:模拟题: 重写父类方法equals

Luz3年前 (2021-05-10)题库598
在类Point中重写Object类的equals方法。使Point对象x和y坐标相同时判定为同一对象。


### 裁判测试程序样例:
```java
import java.util.Scanner;
class Point {
private int xPos, yPos;
public Point(int x, int y) {
xPos = x;
yPos = y;
}
@Override
/* 请在这里填写答案 */
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Object p1 = new Point(sc.nextInt(),sc.nextInt());
Object p2 = new Point(sc.nextInt(),sc.nextInt());
System.out.println(p1.equals(p2));
sc.close();
}
}
```

### 输入样例:

```in
10 20
10 20
```

### 输出样例:

```out
true
```






答案:若无答案欢迎评论

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。