public class tirgon {
double a,b,c;
tirgon(){}
tirgon(double a,double b,double c)
{
setABC(a,b,c);
}
void setABC(double a,double b,double c)
{
tirgon tir=new tirgon();
tir.a=a;
tir.b=b;
tir.c=c;
}
}
class testtirgon
{
public static void main(String args [])
{
tirgon tir=new tirgon(3,4,5);
System.out.println("三角形的边是:"+tir.a+","+tir.b+","+tir.c+",");
}
}
编译出错
改成如下就可以我知道是this的缘故 但我总是弄不清楚this是怎么一回事 望高人指点
public class tirgon {
double a,b,c;
tirgon(double a,double b,double c)
{
setABC(this,a,b,c);
}
void setABC(tirgon tir,double a,double b,double c)
{
tir.a=a;
tir.b=b;
tir.c=c;
}
}
class testtirgon
{
public static void main(String args [])
{
tirgon tir=new tirgon(3,4,5);
System.out.println("三角形的边是:"+tir.a+","+tir.b+","+tir.c+",");
}
}