Question: You will create a base class for a vehicle and extend it to represent specific types of vehicles, applying inheritance and encapsulation principles. Task 1
You will create a base class for a vehicle and extend it to represent specific types of
vehicles, applying inheritance and encapsulation principles.
Task : Create the Vehicle Base Class Marks
Attributes:
String make
String model
int year
int speed
Methods:
A constructor to initialize make, model, and year.
A method accelerate that increases the speed by
A method brake that decreases the speed by ensure the speed does not go below
A method displayInfo that prints the vehicle's make, model, year, and current speed.
Requirements:
Ensure that all the attributes in the Vehicle class are private and provide getter and setter
methods for each attribute.
Test the functionality by creating a Vehicle object and calling the methods to validate
their behavior.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
