
Java学习,在第三行与第四行报错,说参数长度不同??怎么解决呢?
4个回答
展开全部
试了,没有错误
public class Equals {
/**
* @param args
*/
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 w,h;
public Cat(){}
public Cat(int color,int w,int h){
this.color = color;
this.h = h;
this.w = w;
}
public boolean equals(Object c){
if(c==null){
return false;
}else{
if(c instanceof Cat){
Cat cat = (Cat)c;
if(this.color==cat.color&&this.h==cat.h&&this.w==cat.w){
return true;
}
}
}
return false;
}
}
public class Equals {
/**
* @param args
*/
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 w,h;
public Cat(){}
public Cat(int color,int w,int h){
this.color = color;
this.h = h;
this.w = w;
}
public boolean equals(Object c){
if(c==null){
return false;
}else{
if(c instanceof Cat){
Cat cat = (Cat)c;
if(this.color==cat.color&&this.h==cat.h&&this.w==cat.w){
return true;
}
}
}
return false;
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把第16行的 void 去掉,cat改成Cat.
原因解释:因为你的构造函数格式错误。
如果满意,请采纳。
原因解释:因为你的构造函数格式错误。
如果满意,请采纳。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把16行那个void删除了,构造函数里面不能用这个关键字!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
构造函数不能有返回类型,你那个构造函数有void
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询