Preparation of a java program to design an auto Vehicle, comprising wheel properties and a number of vehicle wheels heavy weight. Car Class Car is a subclass of the Vehicle, including the number of attributes are manned loader. Truck Truck class is a subclass of Car class, which contains the attributes load payload. Each class has a constructor and a method of outputting data.
code show as below:
(1 ) Source Code
public class Vehicle {
int wheels;
double weights;
Vehicle ( int Wheels, Double weights) {// This is the constructor
this.wheels=wheels;
this.weights=weights;
}
void disMessage(){
. The System OUT .println ( "the number of the car wheels are" + wheels + "weight of" + weights + "kg");
}
public static void main(String[] args){
Vehicle v=new Vehicle(8,10.00);
smallCar c=new smallCar(6);
Truck t=new Truck(10);
v.disMessage ();
c.disM();
t.disM2();
t.disM3();
}
}
class smallCar extends Vehicle{
int loader;
smallCar(int loader){
super(8,10.00);
this.loader=loader;
}
void disM(){
. The System OUT .println ( "This car can carry" + loader + "man");
}
}
class Truck extends smallCar{
int payload;
Truck(int payload){
super(6);
this.payload=payload;
}
void disM2(){
. The System OUT .println ( "truck load of this" + payload + "kg") ;
}
void disM3(){
. System OUT .println ( "This truck has a" + wheels + "wheels" + "vehicle weight has" + weights + "jin" + "may contain" + loader + "people" + "load of" + payload + "jin");
}
}