Question: hi for this code do i need to seperate the vehicle rental class and the main class? class Vehicle{ public void drive(){ System.out.println(Driving a vehicle!);
hi for this code do i need to seperate the vehicle rental class
and the main class?
class Vehicle{
public void drive(){
System.out.println("Driving a vehicle!");
}
}
class Car extends Vehicle{};
class Van extends Vehicle{};
class MotorCycle extends Vehicle{};
class VehicleRental
public void rent(Vehicle v) {
v.drive();
}
}
public class Main {
public static void main(String[] args) {
VehicleRental
vr1.rent(new Car());
VehicleRental
vr2.rent(new Van());
VehicleRental
vr3.rent(new MotorCycle());
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
