package ch4.object;public class TestEquals {public static void main(String[] args) {Cat c1 = new Cat();c1.color = 1;c1.height = 10;c1.weight = 500;Cat c2 = new Cat();c2.color = 1;c2.height = 10;c2.weight = 500;System.out.println(c1.equals(c2));}}class Cat{int color;int height, weight;public boolean equals(Object obj) {if(obj == null)return false;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 boolean equals(Object obj) {/*if(obj == null) return false;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;*///return true;//}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。