按要求编写一个Java应用程序:

按要求编写一个Java应用程序:
(1)定义一个类,描述一个矩形,包含有长、宽两种属性,和计算面积方法。
(2)编写一个类,继承自矩形类,同时该类描述长方体,具有长、宽、高属性,
和计算体积的方法。
(3)编写一个测试类,对以上两个类进行测试,创建一个长方体,定义其长、
宽、高,输出其底面积和体积。
manlin1008 1年前 已收到1个回答 举报

具体cc量 幼苗

共回答了27个问题采纳率:85.2% 举报

class rectangle
{
private int x;
private int y;

rectangle(int x,int y)
{
this.x=x;
this.y=y;
}
public int acreage()
{
retrun x*y;
}
}

class cuboid extends rectangle
{
private int z;
cuboid(int x,int y,int z)
{
super(x,y);
this.z=z;
}

public int cubage()
{
return x*y*z;
}
}

publicclass Test {
publicstaticvoid main(String[] args){

cuboid c =new cuboid(2,3,4);
int i = c.cubage();

System.out.println("体积:"+ i);
}


}

1年前

2
可能相似的问题
Copyright © 2024 YULUCN.COM - 雨露学习互助 - 16 q. 0.452 s. - webmaster@yulucn.com