private String brand;
private String color;
private double speed=0;
Vehicle(String brand, String color) {
this.brand = brand;
this.color = color;
}
void Vehicle(String brand, String color, double speed) {
this.brand = brand;
this.color = color;
this.speed = speed;
}
void run() {
System.out.println("这个汽车的品牌为"+this.brand+"这个汽车的颜色为"+this.color+"这个汽车的速度为"+this.speed);
}
public static void main(String[] args) {
Vehicle v=new Vehicle("benz","black");
v.run();
v.Vehicle("benz", "black", 300);
v.run();
}
定义一个汽车类Vehicle,要求如下:[选做题] 2.1属性包括:汽车品牌brand(String类型)、颜色color(String类型)和速度speed(double类型),并且所有属性为私有。
最新推荐文章于 2023-01-09 22:24:14 发布