-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathColorPoint.java
More file actions
45 lines (39 loc) Β· 1.25 KB
/
Copy pathColorPoint.java
File metadata and controls
45 lines (39 loc) Β· 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package Chapter3.Day10;
import java.awt.*;
public class ColorPoint extends Point {
private final Color color;
public ColorPoint(int x, int y, Color color) {
super(x, y);
this.color = color;
}
/**
* μμ ν΄λμ€ Point μ equals λ νμ ν΄λμ€λ Point λ x, y λ§ λΉκ΅νλ λ°λ©΄,
*
* μ΄ ν΄λμ€μ equals λ ColorPoint μ κ°μ²΄κ° μλλ©΄ 무쑰건 False λ°ν
*
* λμΉμ± μλ°
*/
// @Override
// public boolean equals(Object o) {
// if (!(o instanceof ColorPoint)) {
// return false;
// }
// return super.equals(o) && ((ColorPoint) o).color == color;
// }
/**
* λμΉμ± μλ°μ κ³ μΉκΈ° μν΄
*/
@Override
public boolean equals(Object o) {
// μνΌν΄λμ€ Point κ° μλκ±°λ Point λ₯Ό μμνμ§ μμκ²λ§ false
if (!(o instanceof Point)) {
return false;
}
// μμμ κ±Έλ¬μ§ κ² μ€ μ΄ μ‘°κ±΄μ λ§λ κ²μ Point κ°μ²΄μΈ κ²λ€
// Point κ°μ²΄λΌλ©΄ Point μ equals μ¬μ©
if (!(o instanceof ColorPoint)) {
return o.equals(this);
}
return super.equals(o) && ((ColorPoint) o).color == color;
}
}