1.equals、==
package com.zrs.demo02;
public class Demo01 {
public static void main(String[] args) {
Dog dog1 = new Dog("xiaohuang");
Dog dog2 = new Dog("xiaohuang");
String s1 = dog1.toString();
String s2 = dog2.toString();
String s3 = "xiaohuang";
String s4 = "xiaohuang";
System.out.println("dog1:" + dog1 + " " + "dog2:" + dog2 + "\t" +
"dog1.equals(dog2):" + dog1.equals(dog2));
System.out.println("s1:" + s1 + " " + "s2:" + s2 + "\t\t" +
"s1.equals(s2):" + s1.equals(s2));
System.out.println("s3:" + s3 + "\t\t\t" + "s4:" + s4 + "\t\t\t\t" +
"s3.equals(s4):" + s3.equals(s4));
System.out.println("dog1:" + dog1 + " " + "dog2:" + dog2 + "\t" +
"dog1 == dog2:" + (dog1 == dog2));
}
}
class Dog {
private String name;
public Dog() {
super();
// TODO Auto-generated constructor stub
}
public Dog(String name) {
super();
this.name = name;
}
}
运行结果: