实验任务三(面向对象基础一)
Java的课堂小实验报告,放上来水一下
可以帮助一些刚入门不想写类似实验报告的人(误)
- 设计一个汽车类Vehicle,包含的成员属性有车轮个数wheels和车重weight。小车类Car是Vehicle的子类,其中包含属性载人数。卡车Truck是Vehicle的子类,其中包含载人数和载重量payload。每个类都有相关数据的输出方法。
代码:
class Vehicle{
int wheel,weight;
protected Vehicle(int wheel,int weight){
this.wheel=wheel;
this.weight=weight;
}
protected Vehicle(){
}
void setwheel(int wheel){
this.wheel=wheel;
}
void displaywheel(){
System.out.println("车辆的轮子为:"+wheel);
}
void setweight(int weight){
this.weight=weight;
}
void displayweight(){
System.out.println("车辆的重量为:"+weight);
}
}
class car extends Vehicle{
public car(int wheel,int weight,int number){
super(wheel,weight);
this.number=number;
}
public car(){
}
int number;
void setNum(int number