验证中...
语言: Java
分类: 其他
最后更新于 2018-04-17 18:12
gistfile1.txt
原始数据 复制代码
public class Test {
public static void main(String[] args) {
Vehicles x=new Vehicles("奔驰","黑色");
x.run();
x.showInfo();
Car y=new Car("宝马","白色",5);
y.run();
y.showInfo();
y.showCar();
Truck t=new Truck("法拉利","黄色",6.5f);
t.run();
t.showInfo();
t.showTruck();
Vehicles m=new Car("宝马","白色",5);
m.run();
m.showInfo();
}
}
//车类
class Vehicles{
String brand;
String color;
public Vehicles(String brand, String color) {
super();
this.brand = brand;
this.color = color;
}
public void run() {
System.out.println("我已经开动了");
}
public void showInfo() {
System.out.println("商标:"+brand+" "+"颜色:"+color);
}
}
//小汽车
class Car extends Vehicles{
int seats;
public Car(String brand,String color,int seats){
super(brand, color);
this.seats=seats;
}
public void run() {
System.out.println("我已经跑动了");
}
public void showInfo() {
System.out.println("商标:"+brand+" "+"颜色:"+color);
}
public void showCar() {
System.out.println("座位:"+seats);
}
}
//卡车类
class Truck extends Vehicles{
float load;
public Truck(String brand, String color, float load) {
super(brand, color);
this.load = load;
}
public void run() {
System.out.println("我已经走动了");
}
public void showInfo() {
System.out.println("商标:"+brand+" "+"颜色:"+color);
}
public void showTruck(){
System.out.println("载重:"+load);
}
}

评论列表( 0 )

你可以在登录后,发表评论

搜索帮助