Java基础 继承 程序设计

设计一个长方形的类,其私有数据成员为长方形的长和宽,写出构造方法初始化长和宽,并分别写出成员方法求长方形的面积和周长。

继承长方形类,设计长方体的类,新增私有成员为长方体的高,写出构造方法方法初始化长方体的数据成员,并写成员方法求长方体的体积.

编写主类,创建长方体对象,输出长方体的底面积、周长以及长方体的体积。


class rectangle
{
   private int length;
   private int wide;
   rectangle(int length,int wide)
   {
      this.length = length;
      this.wide = wide;
   }
   public int getC()
   {
      return 2*(this.length+this.wide);
   }
   public int getA()
   {
      return this.length*this.wide;
   }
}
class ti extends rectangle
{
   private int height;
   ti(int length,int wide,int height)
   {
   super(length,wide);
   this.height = height;
   }
   public int volume()
   {
      return super.getA()*height;
   }
}
public class sth413
{
   
   public static void main(String[] args)
   {
      ti t = new ti(3,4,5);
      System.out.println(t.getC());
      System.out.println(t.getA());
      System.out.println(t.volume());

   }
}