Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes
Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes: Ø “Car” that inherits “Vehicle” and also stores number of passengers. Ø “Truck” that inherits “Vehicle” and also stores the load limit. Write a main() function to create objects of these classes and display all the information about Car and Truck. Also, compare the speed of the two vehicles, Car and Truck and display “faster” or “slower” if Car is faster or slower than Truck. import java.util.*; class Vehicle{ int wheels; double speed; } class Car extends Vehicle{ int pass; void input(){ Scanner sc=new Scanner(System.in); System.out.println("Enter the car's details:\nNo. of wheels:"); wheels=sc.nextInt(); System.out.println("Speed of Car(Km/hr):"); speed=sc.nextDouble(); System.out.println("No. of passengers:"); ...
Comments
Post a Comment