piepew 2021-06-15 12:14 采纳率: 33.3%
浏览 25
已采纳

求大神这题该怎么做,谢谢

 

  • 写回答

5条回答 默认 最新

  • piepew 2021-06-16 15:05
    关注
    package add;
    import java.util.*;
     class Rectangle{             //不需要添加public
    	  double length;
    	  double width;
    	 public Rectangle(){}      //有无不重要
    	 public Rectangle(double length,double width){  //构造函数
    	       this.length=length;
    	       this.width=width;}
    	    public double area(double length,double width){   //重写方法
    	      double Area=length*width;
    	    return Area;
    	    }
    	    public void showInfo(){
    	     System.out.println("底面积Area="+length*width);
    	    }
    	}
    	   class Cuboid extends Rectangle{
    	   double height;
    	   public Cuboid(){}
    	   public Cuboid(double length,double width,double height){
    	   super(length,width);
    	   this.height=height;
    	}
    	   public double Volume(){
    	   double volume=length*width*height;
    	   return volume;
    	}
    	   public void showInfo(){
    	   System.out.println("体积volume="+length*width*height);
    	}
    	}
    	  public class test{
    	  public static void main(String[] args){
    	  Rectangle c2 = new Rectangle(3.1,4.2);
    	  c2.showInfo();
    	  Cuboid c1 = new Cuboid(3.1,4.2,5.3);
    	  c1.showInfo();
    }
    }
    	  
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?