比较运算符和equals

2021-11-03  本文已影响0人  哈迪斯Java
image.png

package HspLearningPoly.poly01;

public class ObjPerson {
public static void main(String[] args) {
Person person1 = new Person();
person1.name = "yang";

    Person person2 = new Person();
    person2.name = "yang";

    System.out.println(person1 == person2);
    System.out.println(person1.name.equals(person2.name));
    System.out.println(person1.equals(person2));

    String s1 = new String("abs");
    String s2 = new String("abs");

    System.out.println(s1.equals(s2));
    System.out.println(s1 == s2);

}

}

class Person {
public String name;
}
false
true
false
true
false

上一篇下一篇

猜你喜欢

热点阅读