我正在使用==运算符比较2个Java对象,有人可以解释为什么打印"b"而不是"a"?
public class punktAusfuehren {
Punkt p1 = new Punkt(19, 10);
Punkt p2 = new Punkt(5, 0);
public static void main(String[] args) {
new punktAusfuehren();
}
public punktAusfuehren() {
if (p1 == p2) {
System.out.println("a");
} else {
System.out.println("b");
}
if (p1 instanceof Punkt) {
System.out.println("c");
} else {
System.out.println("d");
}
}
}
Run Code Online (Sandbox Code Playgroud)