JAVA第四章实验.docVIP

  • 9
  • 0
  • 约5.82千字
  • 约 9页
  • 2016-12-11 发布于重庆
  • 举报
第四章实验 对象的创建和使用 Rectangle是一个矩形类,该类包含两个成员变量width和length分别表示矩形的宽和长。成员方法area()用来计算矩形的面积。试填写下列程序中的空白部分,以输出一个宽为2.5长为8.7的举行的面积。 (提示:应首先填写Rectangle的构造函数)。 class JLab0401{ public static void main(String[] args){ Rectangle myRect = new Rectangle(2.5,8.7);double theArea; theArea = myRect.area(); System.out.println(My rectangle has area + theArea); } } //end of class JLab0401 class Rectangle{ double width, length; Rectangle(double widthd,double lengthd){ width=widthd; length=lengthd; } public double area(){ double a; a = length * width; return a; } } //end of class Rectangle 编译并执行你填写完整的程序。 (3)在上述程序

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档