public class Vehicle {
private String speed;
private String kind;
private String color;
public Vehicle(String speed, String kind, String color) {
super();
this.speed = speed;
this.kind = kind;
this.color = color;
}
public String getSpeed() {
return speed;
}
// 设置速度
public void setSpeed(String speed) {
this.speed = speed;
}
// 取得类别
public String getKind() {
return kind;
}
public void setKind(String kind) {
this.kind = kind;
}
// 取得颜色
public String getColor() {
return color;
}
// 设置颜色
public void setColor(String color) {
this.color = color;
}
// 重写toSting方法
@Override
public String toString() {
return "Vehicle [color=" + color + ", kind=" + kind + ", speed="
+ speed + "]";
}
public static void main(String[] args) {
Vehicle v = new Vehicle("100", "汽车", "红色");
// 设置新的速度和颜色
v.setColor("绿色");
v.setSpeed("200");
System.out.println(v);
}
}
有不懂的可以继续问。方法有没用的自己会去掉吧!方法写的比较全。也可以做其他问题。
希望能帮助到你