这几个类是写在一起的还是?
每个类应该都是有构造方法的或者volume,weight这几个方法是要传参数的,但是你的方法是没有传参
s1=length*width*high;运算要放到方法体内,还有属性私有化之后不能被继承,除了Cuboid类本身,其他类都没法直接访问到
你把属性设置为私有的 不能继承
public class Cuboid
{
protected double length;
protected uble width;
protected double high;
protected ouble s1;
protected double s2;
protected ouble s3;
publc void volume()
{
s1=length*width*high;
System.out.println(s1);
}
}
public class CuboidWeight extends Cuboid
{
prodected double density;
public void weight()
{
s2=length*width*high*density;
System.out.println(s2);
}
}
public class CuboidValue extends CuboidWeight
{
double value;
public void none()
{
s3=length*width*high*density*value;
System.out.println(s3);
}
}
class Demo333
{
public static void main(String[] args)
{
length=1;
width =2;
high=3;
density=4;
value=5;
CuboidValue cubo=new CuboidValue();
cubo.volume();
cucuboeight();
cubo. none();
}
}