纪念一下,第一次写一个程序首次运行就得到了自己想要的结果,哈哈,悲催的表扬自己一下啊!
class Test
{ int i,j; Test(int a,int b) //构造函数 { i=a; j=b; } boolean comp( Test obj) { if(obj.i==i&&obj.j==j) return true; else return false; } } public class test1
{ public static void main(String[] args) { boolean result; Test obj1 =new Test(3,5); //对象作为实参 Test obj2 =new Test(5,7); Test obj3 =obj1; //引用obj3和obj1同时指向对象Test(3,5); obj3和obj1并无其他联系 result =obj1.comp(obj2); System.out.println("obj1==obj2 is "+ result); result =obj2.comp(obj3); System.out.println("obj2==obj2 is "+ result); result =obj3.comp(obj1); System.out.println("obj1==obj3 is "+ result); } } |
|