天涯CCY
2018-03-04 15:10
package com.imooc;
public class infial {
public static void main(String[] args) {
// TODO Auto-generated method stub
Telephone tele=new Telephone();
tele.size=10;
tele.CPU=10;
tele.Memory=10;
Telephone tele1=new Telephone();
tele.size=10;
tele.CPU=10;
tele.Memory=10;
if(tele.equals(tele1)){
System.out.println("两个对象是相同的");
}
else{
System.out.println("两个对象是不相同的");
}
}
}
package com.imooc;
public class Telephone {
int size;
int CPU;
int Memory;
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Telephone other = (Telephone) obj;
if (CPU != other.CPU)
return false;
if (Memory != other.Memory)
return false;
if (size != other.size)
return false;
return true;
}
}
问题在给第二个tele1你写成了tele
Java入门第二季 升级版
530646 学习 · 6091 问题
相似问题