请问compare的用法是怎样的?它到底比较的是什么?
例如:class CCircle
{
private static double pi=3.14;
private double radius;
public CCircle(double r){
radius=r;
}
public void compare(CCircle cir){
if(this.radius==cir.radius)
//return this;
System.out.println("objects are equal");
else
//return cir;
System.out.println("objects are not equal");
}
}
public class app7_4
{
public static void main(String args[])
{
CCircle cir1=new CCircle(1.0);
CCircle cir2=new CCircle(1.0);
cir1.compare(cir2);
}
}
跟下面的代码有什么区别:
class CCircle
{
private static double pi=3.14;
private double radius;
public CCircle(double r){
radius=r;
}
public void compare(CCircle cir){
if(this==cir)
//return this;
System.out.println("objects are equal");
else
//return cir;
System.out.println("objects are not equal");
}
}
public class app7_4
{
public static void main(String args[])
{
CCircle cir1=new CCircle(1.0);
CCircle cir2=new CCircle(1.0);
cir1.compare(cir2);
}
}
请解释一下好吗?
[此贴子已经被作者于2007-4-19 12:05:03编辑过]