急求设计一车类的java答案,具有wheels和weight两属性,汽车类car是vehicle类的子

来源:百度知道 编辑:UC知道 时间:2024/06/19 20:58:46

public class Car extends Vehicle {
private Wheels wheels = null;//不知道您的轮子是不是类 当类处理了
private Weight weight = null;//同上
}

//最简单的先
public class Vehicle {
private int wheels ;//轮子个数
private int weight ;
}

public class Car extends Vehicle {

public Car()
{
wheels = 4;
weight = 1000;//随便写的

}

}

要是要求wheels 和 weight 满足更多的需求,那就要再设计Wheels 类
把int换了,下面给你个例子
public class Wheels
{
private int num; //轮子个数
private int size; //轮子大小
private String attribute ; //轮子的产地,型号。。。。
private int price ; //轮子价格

}