if(c.color == this.color && c.height == this.height && c.wei
来源:学生作业帮 编辑:拍题作业网作业帮 分类:综合作业 时间:2024/05/19 06:49:47
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;
}
}
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;
}
}
this 表示你要执行操作的类对象,比如你定义了Object a1;并进行初始化,现在a1.equal(Object boj),这个时候this就代表的是a1这个类对象的指针.可以调用a1中的成员
if(c.color == this.color && c.height == this.height && c.wei
关于昆虫的句子.baidu{font-size:14px;line-height:1.5;}a{color:#0000c
秋天开花的植物.baidu{font-size:14px;line-height:1.5;}a{color:#0000c
What's this color?=------- --------is it?
left=480 top=390 width=50 height=200 font=40 color=$00FF00 #
$this->data['comment']=''; if (isset($this->session->data['c
This wall is taller than that one in its() A.height B.size C
请问从语言if( (ps+i)->height > (ps+i+1)->height )pmax=ps;中"->"是什么
1.i like this color .do you want to__one?a.need b.help c.tak
What_____is this?It's“A”.A:it; B:in; C:color; D:letter
what color is this
He is of medium height .=He is medium height .=He has a medi