Created
March 21, 2020 07:04
-
-
Save ababup1192/5ba0db5566b51e47c290a8495d54852d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String args[]) { | |
Point p1 = new Point(1, 1); | |
Point p2 = new Point(2, 3); | |
Point p3 = new Point(1, 1); | |
// false | |
System.out.println(p1.equals(p2)); | |
// true | |
System.out.println(p1.equals(p3)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Point { | |
// フィールド | |
private int x; | |
private int y; | |
// コンストラクタ | |
public Point(int x, int y) { | |
this.x = x; | |
this.y = y; | |
} | |
public boolean equals(Object object) { | |
if (object == null || !(object instanceof Point)) { | |
return false; | |
} | |
Point target = (Point) object; | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment