(*)定义机动车类,具有属性:车牌号、车速和载重量,具有功能:加速、减速。一个构造方法没有形参,在方法中将车牌号设置为“辽A1234”,速度为100,载重量为50;另一个构造方
package gh; public class vehicle { String vehicl_Number; int vehicl_speed; int vehicl_loadVolume; public vehicle() { super(); vehicl_Number="辽A1234"; vehicl_speed=100; vehicl_loadVolume=50; } public vehicle(String vehicl_Number, int vehicl_speed, int vehicl_loadVolume) { super(); this.vehicl_Number = vehicl_Number; this.vehicl_speed = vehicl_speed; this.vehicl_loadVolume = vehicl_loadVolume; } int accelerate(int x){ vehicl_speed+=x; return vehicl_speed; } int decelerate(int x){ vehicl_speed-=x; return vehicl_speed; } } package gh; public class text8 { public static void main(String[] args) { vehicle myVehicle1=new vehicle(); vehicle myVehicle2=new vehicle("辽B5678",80,20); myVehicle2.decelerate(20); System.out.println(myVehicle1.vehicl_Number+" "+myVehicle1.vehicl_speed+" "+myVehicle1.vehicl_loadVolume); System.out.println(myVehicle2.vehicl_Number+" "+myVehicle2.vehicl_speed+" "+myVehicle2.vehicl_loadVolume); } }