1、 试题序号:601 2、 题型:程序编写题 3、 难度级别:2 4、 知识点:类
试题序号:601
题型:程序编写题
难度级别:2
知识点:类和对象的创建,构造函数(4-1)
分值:10
所需时间:15
试题关键字:
试题内容:
编写一个矩形类Rect,包含:
两个protected属性:矩形的宽width;矩形的高height。
两个构造器方法:
(1)一个带有两个参数的构造器方法,用于将width和height属性初化;
(2)一个不带参数的构造器,将矩形初始化为宽和高都为10。
两个方法:
求矩形面积的方法area()
求矩形周长的方法perimeter()
答案内容:
class Rect{
protected double width,height;
public Rect(double width,double height){
this.width=width;
this.height=height;
}
public Rect(){
width=10;
height=10;
}
public double area(){
return width*height;
}
public double perimeter(){
return 2*(width+height);
}
}
评分细则:
属性定义:3分;
构造器方法:3分;
方法实现:4分;
试题序号:602
原创力文档

文档评论(0)