0% found this document useful (0 votes)
37 views1 page

Vehicle Class Design Concepts

Uploaded by

dennisdionsay2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views1 page

Vehicle Class Design Concepts

Uploaded by

dennisdionsay2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

SHORT REPORT:

 Encapsulation:

 Encapsulation is applied by hiding the internal details of the Vehicle, Car, and
Motorcycle classes using private instance variables (e.g., brand, model, year). The
access to these properties is provided via public getter methods such as getBrand(),
getModel(), and getYear(). This ensures that the internal state is protected from direct
access and modification by external code.

 Inheritance:

 The concept of inheritance is implemented by creating subclasses Car and Motorcycle


that extend the abstract Vehicle class. This allows Car and Motorcycle to inherit the
common properties and methods of Vehicle, such as brand, model, year, and
displayInfo(). Each subclass adds specific attributes like numberOfDoors for Car and
hasSidecar for Motorcycle, showcasing the reusability of code.

 Polymorphism:

 Polymorphism is demonstrated through the overriding of methods. The method


getVehicleType() is abstract in Vehicle and is implemented differently in the
subclasses ("Car" for Car and "Motorcycle" for Motorcycle). Additionally, the
displayInfo() method is overridden in both Car and Motorcycle to include details
specific to each type of vehicle. At runtime, polymorphism allows us to call the same
method on objects of different types, resulting in different behavior.

 Abstraction:

 Abstraction is applied through the Vehicle class, which defines a general blueprint for a
vehicle. The getVehicleType() method is abstract and must be implemented by
subclasses, forcing them to provide their own implementation. This allows the program to
work with general Vehicle references while hiding the specific details of each vehicle
type

You might also like