Java中的小问题

来源:百度知道 编辑:UC知道 时间:2024/05/27 16:59:40
class Box
{
private float a,volume;
Box(float r)
{r=a;}
seta()
{
return a();
}
getvolume()
{
return volume();
}
public void display();
System.out.println("±ß³¤="+a+";Ãæ»ý="+ a*a*a);
}
class BoxTest
{
public static void main(String args[])
{
Box a=new Box();
a.seta();
{a=5;}
a.getvolume();
a.display();
}
}

错误好多啊
你的问题是什么

public class Box {
private float a,volume;
public Box(){}//因为TEST里面用到了
Box(float r)
{a=r;}
public float seta(){
return a;
}
public float getvolume()
{
return volume;
}
public void display(){
System.out.println("±ß³¤="+a+";Ãæ»ý="+ a*a*a);
}

}
class BoxTest
{
public static void main(String args[])
{
Box a=new Box(5);
//想用set就要先定义,你上面定义的set方法
a.getvolume();
a.display();
}
}
//最后就是你的命名都很乱 需要改进

class Box
{
private float a,volume;
Box(float r)
{r=a;}
float seta()
{
return a();
}
float getvolume()
{
return volume();
}
public void display();
System.out.println("±ß³¤="+a+";Ãæ»ý="+ a*a*a);