Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Vehicle {
- int vehicle_no;
- String model;
- String manufacturer;
- String color="yellow";
- public Vehicle(){
- }
- public Vehicle(int vehicle_no, String model, String manufacturer, String color) {
- this.vehicle_no=vehicle_no;
- this.model=model;
- this.manufacturer=manufacturer;
- this.color=color;
- }
- }
- ________________________________________________________
- public class Truck extends Vehicle{
- int loadingCapacity=100;
- public Truck(){
- }
- public Truck(int vehicle_no, String model, String manufacturer, String color, int loadingCapacity) {
- super(vehicle_no,model,manufacturer,color);
- this.loadingCapacity=loadingCapacity;
- }
- void display(){
- System.out.println("Vehicle Number: "+vehicle_no);
- System.out.println("Model: "+model);
- System.out.println("Manufacturer: "+manufacturer);
- System.out.println("Loading Capacity is: "+loadingCapacity);
- System.out.println("Color is: "+color);
- }
- }
- _____________________________________________________________
- public class Application {
- public static void main(String args[]){
- Scanner scanner=new Scanner(System.in);
- System.out.println("Truck no. is: ");
- int vehicle_no=scanner.nextInt();
- System.out.println("Model is: ");
- String model=scanner.next();
- System.out.println("Manufacturer is: ");
- String manufacturer=scanner.next();
- System.out.println("Color is: ");
- String color=scanner.next();
- System.out.println("Loading capacity is: ");
- int loadingCapacity=scanner.nextInt();
- Vehicle vehicle=new Vehicle();
- System.out.println();
- System.out.println("Before changing color is: "+vehicle.color);
- Truck truck1=new Truck();
- Truck truck=new Truck(vehicle_no,model,manufacturer,color,loadingCapacity);
- System.out.println("Previous capacity is: "+truck1.loadingCapacity);
- System.out.println("\nTruck details");
- truck.display();
- scanner.close();
- }
- }
Add Comment
Please, Sign In to add comment