更新时间: 试题数量: 购买人数: 提供作者:

有效期: 个月

章节介绍: 共有个章节

收藏
搜索
题库预览
创建一个桌子类table,该类中有桌子名称、重量、桌面宽度和长度、桌子高度等属性,并含有以下几个方法。 (  ) 构造方法:初始化所有成员变量; (  ) area(  ): 计算桌面的面积; (  ) display(  ): 在屏幕上输出所有成员变量的值; (  ) changeweight(int w):改变桌子重量; 在main(  )方法中实现创建一个桌子对象,计算桌面地面积,改变桌子重量,并在屏幕上输出所有桌子地属性值。 解:代码如下: //注:全部准确完成得满分。 public class table { //注:完成以下属性定义得1分。 private String name; private int weight; private int length; private int width; private int height; //注:完成构造方法设计得2分。 public table(String name, int weight, int length, int width, int height) { this. name=name; this. weight=weight; this. length=length; this. width=width; this. height=height; } //注:完成dispaly(  )方法设计得2分。 public void dispaly(  ) { System.out.println(  ); System.out.println(  ); System.out.println(  ); System.out.println(  ); System.out.println(  ); } //注:完成area(  )方法设计得2分。 int area(  ) { int area; area=length*width; return area; } //注:完成changeweight(  )方法设计得1分。 void changeweight(int w) { weight=w; } //注:完成main(  )方法设计得2分。 public static void main(String[] args) { table ta =new table("桌子", 100, 10, 10, 10); ta.dispaly(  ); int x; x=ta.area(  ); System.out.println(  ); ta.changeweight(  ); ta.dispaly(  ); } } ----------------------------------------------------------------------------------------- :Java继承性与多态性