if(c.color == this.color && c.height == this.height && c.weight == this.weight) 这里this指的是?public class TestEquals { public static void main (String[] args) { Cat c1 = new Cat(1,2,3); Cat c2 = new Cat(1,2,3); System.out.println(c1 == c2);

来源:学生作业帮助网 编辑:作业帮 时间:2024/11/19 09:31:41
if(c.color == this.color && c.height == this.height && c.weight == this.weight) 这里this指的是?public class TestEquals { public static void main (String[] args) {  Cat c1 = new Cat(1,2,3);  Cat c2 = new Cat(1,2,3);  System.out.println(c1 == c2);
xTn@lr]keX$qS!H*̫TЧD$TMC՟8_`' {s{ZsŪJj끮[Tتa m,!ܽj|+gNz30lFOV!'}׺ r@Z#n|1"`Ao@*+5"yu dۑ:JBRύ ݘX"Tx9g/.t?(hkch&hLbnض &@q^$!ϰ6knw==P̎ >V&߾ӚnxZE bN3sRsE0\($ݓcr8

if(c.color == this.color && c.height == this.height && c.weight == this.weight) 这里this指的是?public class TestEquals { public static void main (String[] args) { Cat c1 = new Cat(1,2,3); Cat c2 = new Cat(1,2,3); System.out.println(c1 == c2);
if(c.color == this.color && c.height == this.height && c.weight == this.weight) 这里this指的是?
public class TestEquals {
public static void main (String[] args) {
Cat c1 = new Cat(1,2,3);
Cat c2 = new Cat(1,2,3);
System.out.println(c1 == c2);
System.out.println(c1.equals(c2));
}
}
class Cat {
int color;
int height,weight;
public Cat (int color, int height, int weight) {
this.color = color;
this.height = height;
this.weight = weight;
}
public boolean equals(Object obj) {
if(obj == null) return false;
else {
if(obj instanceof Cat) {
Cat c = (Cat)obj;
if(c.color == this.color && c.height == this.height && c.weight == this.weight) {
return true;
}
}
}
return false;
}

}

if(c.color == this.color && c.height == this.height && c.weight == this.weight) 这里this指的是?public class TestEquals { public static void main (String[] args) { Cat c1 = new Cat(1,2,3); Cat c2 = new Cat(1,2,3); System.out.println(c1 == c2);
this 表示你要执行操作的类对象,比如你定义了Object a1;并进行初始化,现在a1.equal(Object boj),这个时候this就代表的是a1这个类对象的指针.可以调用a1中的成员