java编程:定义一个长方形类,含有成员变量:长length, 宽width;成员方法:构造方法,
答案:3 悬赏:30
解决时间 2021-03-02 14:15
- 提问者网友:芷芹
- 2021-03-01 13:28
java编程:定义一个长方形类,含有成员变量:长length, 宽width;成员方法:构造方法,求面积方法。再定义一个长方体类Cube,从长方形类中继承,含有成员变量:高 height,成员方法:构造函数,求体积的方法。
最佳答案
- 二级知识专家网友:迷人小乖乖
- 2021-03-01 13:39
public class rectangle {
long length;
long width;
rectangle(long length, long width) {
this.length = length;
this.width = width;
}
public long getsquare() {
return this.length * this.width;
}
public static void main(string[] args) {
cube cube= new cube(1,1,2);
system.out.println(cube.getvolume());
}
}
class cube extends rectangle {
long height;
cube(long length, long width, long height) {
super(length, width);
this.height = height;
}
public long getvolume() {
return this.getsquare() * height;
}
}
全部回答
- 1楼网友:转身后的回眸
- 2021-03-01 15:40
public class rectangle {
public double length;
public double width;
public rectangle()
{
double area=length*width;
}
}
public class Cube extends rectangle{
public double height;
public Cube() {
rectangle r=new rectangle();
double column=height*r.length*r.width;
}
}
有什么问题再说。
- 2楼网友:不服输的倔强
- 2021-03-01 14:24
长方体继承矩形,无力吐槽
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯