1 public class Vehicle { 2 double speed; 3 double size; 4 Vehicle(){ 5 speed=1.0; 6 size=2.0; 7 } 8 void move(){ 9 }10 void setSpeed(int speed){11 this.speed=speed;12 }13 void setSize(int size){14 this.size=size;15 }16 void speedUp(){17 speed=speed+1;18 System.out.println("汽车加速后的速度为"+speed+"千米/时");19 }20 void speedDown(){21 speed=speed-1;22 System.out.println("汽车减速后的速度为"+speed+"千米/时");23 }24 }25 --------------------------------------------------------------------------------26 public class Test {27 28 public static void main(String[] args) {29 // TODO Auto-generated method stub30 Vehicle aaa=new Vehicle();31 System.out.println("汽车的速度为"+aaa.speed+"千米/时");32 System.out.println("汽车的体积为"+aaa.size+"立方米");33 aaa.speedUp();34 aaa.speedDown();35 }36 37 }