BoxからCubeを拡張したい。私のプログラムには3つの部分があり、最初に長方形のクラスを実行し、次にそれを使用してBoxクラスを拡張し、次にCubeを拡張します。キューブ部分で立ち往生しています。これは私の指示が言うことです:
評価手順a。立方体は、長さ、幅、高さがすべて同じ値を持つボックスです。b。インスタンス変数やメソッドを追加する必要はありませんが、長さ、幅、高さがすべて同じ値になるようにCubeのコンストラクターを設定する必要があります。
矩形:
public class Rectangle
{
// instance variables
private int length;
private int width;
/**
* Constructor for objects of class rectangle
*/
public Rectangle(int l, int w)
{
// initialise instance variables
length = l;
width = w;
}
// return the height
public int getLength()
{
return length;
}
public int getWidth()
{
return width;
}
}
箱:
public class Box extends Rectangle
{
// instance variables
private int height;
/**
* Constructor for objects of class box
*/
public Box(int l, int w, int h)
{
// call superclass
super(l, w);
// initialise instance variables
height = h;
}
// return the height
public int getHeight()
{
return height;
}
}
そしてメインのキューブ:
class Cube extends Box{
// instance variables
private int height;
private int length;
private int width;
public Cube(int h,int w,int l){
super(h,w,l);
}
public double getheight(){
return height;
}
public double getlength() {
return length;
}
public double getwidth() {
return width;
}
}
Cubeを正しく実行したかどうかを知る必要があります。私がそれを正しくしなかったならば、私がそれを直すのを手伝ってください。