//定义汽车类
class Vehicle{
//定义属性
private String brand;
private String color;
private double speed=0.0;
//定义构造方法
public Vehicle(){}
public Vehicle(String brand,String color,double speed){
this.brand=brand;
this.color=color;
this.speed=speed;
}
public String getBrand(){
return brand;
}
public String getColor(){
return color;
}
public double getSpeed(){
return speed;
}
//其他方法
public void run(){
System.out.println("汽车在奔跑");
}
}
//测试类
class VehicleTest{
public static void main(String[] args){
Vehicle v = new Vehicle("benz","black",250);
System.out.println(v.getColor()+"的"+v.getBrand()+"再以"+v.getSpeed()+"km/H的速度奔跑");
v.run();
}
}
定义一个汽车类Vehicle,要求如下: [选做题] 1)属性包括:汽车品牌brand(String类型)、颜色color(String类型)和速度speed(double类型),并且所有属性为
最新推荐文章于 2022-10-09 23:34:45 发布