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 = new VehicleRental<>();

vr1.rent(new Car());

VehicleRental vr2 = new VehicleRental<>();

vr2.rent(new Van());

VehicleRental vr3 = new VehicleRental<>();

vr3.rent(new MotorCycle());

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!