freego1026
发贴: 3
积分: 0
|
于 2005-12-04 00:18
class Test{ int a,b; Test(int i,int j){ //带两个整型参数的构造函数 a=i; b=j; } boolean equals(Test o){ //判断两个对象的实例变量是否相等 //ob1.equals(ob2) 实际上就是说如果obj1.a==obj2.a&&obj1.b==obj2.b //如果相等就返回ture,反之false if(o.a==a && o.b==b) return true; else return false; } } class PassOb{ public static void main(String args[]){ Test ob1=new Test(100,22); Test ob2=new Test(100,22); Test ob3=new Test(-1,-1); System.out.println("ob1==ob2:"+ob1.equals(ob2));
System.out.println("ob1==ob3:"+ob1.equals(ob3)); } }
|