freego1026
发贴: 3
积分: 0
|
于 2005-12-03 23:52
不知道你问什么呢? boolean equals(Test o){ if(o.a==a && o.b==b) return true; else return false; } } 这个函数有用吗这里,后面也没有调用啊!equals()方法本身就是判断两个对象是否相等的,你写的哪个函数不知道有什么意义啊! 不过对象作为参数的时候在函数中只能改变对象的状态,不能改变对象的引用! class Test { int a,b; Test(int i,int j) { a=i; b=j; } void change(Test o) { o.a=30; o.b=40; } public static void main(String args[]) { Test obj=new Test obj(15,20); System.out.println("obj.a="+obj.a+"\t"+"obj.b="+obj.b); obj.change(obj); System.out.println("obj.a="+obj.a+"\t"+"obj.b="+obj.b); } } 这样两次的值是不一样的!对象作为参数的时候在函数中只能改变对象的状态
|