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

OOP Fundamentals

The document outlines a series of exercises focused on Object-Oriented Programming (OOP) concepts. It includes creating classes such as Book, Car, Student, Shape, and Calculator, demonstrating attributes, methods, inheritance, encapsulation, method overriding, and operator overloading. Each exercise encourages instantiation of objects and manipulation of their attributes to reinforce OOP fundamentals.

Uploaded by

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

OOP Fundamentals

The document outlines a series of exercises focused on Object-Oriented Programming (OOP) concepts. It includes creating classes such as Book, Car, Student, Shape, and Calculator, demonstrating attributes, methods, inheritance, encapsulation, method overriding, and operator overloading. Each exercise encourages instantiation of objects and manipulation of their attributes to reinforce OOP fundamentals.

Uploaded by

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

Unit 2.

1: Object-Oriented Programming
Fundamentals
1. Create a class called Book with attributes like title, author, and genre.
Implement methods within the class to set and retrieve these attributes.
Instantiate two objects from the Book class, set their attributes, and
display the information.

2. Define a class named Car with both instance and class attributes.
Provide examples for each. Create objects from the Car class and
demonstrate how to modify both instance and class attributes.

3. Choose a real-world scenario (e.g., electronic devices). Create a class


hierarchy with a base class representing a generic device and derived
classes representing specific devices (e.g., smartphone, laptop).
Instantiate objects from each class and demonstrate how inheritance
simplifies code organization.

4. Create a class named Student with attributes such as name, age, and
roll_number. Define methods within the class to set and retrieve these
attributes. Instantiate two objects from the class, set their attributes,
and display the information.

5. Extend the Student defined previously class defined by you to include


private attributes. Implement getter and setter methods to access and
modify the private attributes. Demonstrate encapsulation by using
these methods.

6. Create a base class Shape with a method to calculate area. Derive


classes Circle and Rectangle from Shape with specific implementations
for area calculation. Instantiate objects of both derived classes and
calculate their areas.

7. Extend the Rectangle class defined previously to override the area


calculation method. Demonstrate method overriding by calculating the
area of a rectangle using the overridden method.

8. Implement a class called Calculator with methods for basic


mathematical operations. Show how method overloading can be
applied to handle different data types. Explore operator overloading by
defining a method in the Calculator class that handles addition for both
numbers and strings.

You might also like