0% found this document useful (0 votes)
14 views2 pages

Assignment 05

Uploaded by

riddhichaskar750
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views2 pages

Assignment 05

Uploaded by

riddhichaskar750
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;

abstract class Vehicle {


String brand;
String model;

public Vehicle(String brand, String model) {


this.brand = brand;
this.model = model;
}
public abstract void displayInfo();

public void startEngine() {


System.out.println("Engine started.");
}
}

class Bike extends Vehicle {

public Bike(String brand, String model) {


super(brand, model);
}
public void displayInfo() {
System.out.println("Bike Brand : " + brand + "Model is : " + model );
}
}

class Car extends Vehicle {

public Car(String brand, String model) {


super(brand, model);

}
public void displayInfo() {
System.out.println("Car Brand : " + brand + "Model is " + model);
}
}

public class AbstractClass {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Bike Brand:");
String bike_brand = sc.nextLine();
System.out.println("Enter the Bike Model:");
String bike_model = sc.nextLine();
System.out.println("Enter the Car Brand:");
String car_brand = sc.nextLine();
System.out.println("Enter the Car Model:");
String car_model = sc.nextLine();

Vehicle myBike = new Bike(bike_brand , bike_model);


Vehicle myCar = new Car(car_brand , car_model);
System.out.println("Bike Details");
myBike.displayInfo();
myBike.startEngine();
System.out.println("Car Details");
myCar.displayInfo();
myCar.startEngine();
}
}

You might also like