Question: Exercise Overview: You will create a base class for a vehicle and extend it to represent specific types of vehicles, applying inheritance and encapsulation principles.

Exercise Overview:
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: Create the Vehicle Base Class (5 Marks)
1. Attributes:
- String make
- String model
- int year
- int speed
2. Methods:
- A constructor to initialize make, model, and year.
- A method accelerate() that increases the speed by 10.
- A method brake() that decreases the speed by 10(ensure the speed does not go below
0).
- A method displayInfo() that prints the vehicle's make, model, year, and current speed.

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 Programming Questions!