0% found this document useful (0 votes)
7 views3 pages

OOP Exam Reviewer

The document is an exam reviewer for Object-Oriented Programming, containing multiple choice questions, code completion exercises, true or false statements, and problem-solving tasks. It covers key concepts such as classes, encapsulation, inheritance, polymorphism, and method overriding in Python. The reviewer includes sample code snippets and answers to facilitate understanding and practice.

Uploaded by

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

OOP Exam Reviewer

The document is an exam reviewer for Object-Oriented Programming, containing multiple choice questions, code completion exercises, true or false statements, and problem-solving tasks. It covers key concepts such as classes, encapsulation, inheritance, polymorphism, and method overriding in Python. The reviewer includes sample code snippets and answers to facilitate understanding and practice.

Uploaded by

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

### Object-Oriented Programming Exam Reviewer

#### MULTIPLE CHOICE QUESTIONS:


Instruction: Encircle the letter of the best answer.

1. Which of the following best describes object-oriented programming?


a. A way to define functions in Python
b. A programming paradigm that organizes data and behavior into objects
c. A method for structuring SQL databases
d. A way to write scripts without using classes

2. What keyword is used to define a class in Python?


a. def
b. class
c. struct
d. object

3. Which method is called automatically when an object is created?


a. __start__
b. __create__
c. __init__
d. __begin__

4. Which of the following demonstrates encapsulation?


a. Using the `private` keyword to restrict access
b. Using a single underscore (_) to indicate protected attributes
c. Bundling data and methods within a class
d. All of the above

5. How do you call a parent class’s constructor inside a child class?


a. parent.__init__()
b. super().__init__()
c. base().__init__()
d. init_parent()

#### CODE COMPLETION (FILL IN THE BLANKS)


Fill in the blanks with the correct code.

6-10: Complete the missing parts of the Python class implementation.


```python
class Animal:
def __init__(self, _____, species):
_____ .species = species

def make_sound(self):
print("Some generic animal sound")

class Dog(_____):
def __init__(self, name, species, breed):
super()._____(name, species)
self.breed = _____

def make_sound(self):
print("Bark!")

dog1 = Dog("Buddy", "Mammal", "Golden Retriever")


dog1.____()
```
Answers: `self`, `self`, `Animal`, `__init__`, `breed`, `make_sound`
#### OBJECT CREATION AND TESTING EXERCISES:
Write code to complete the following exercises.

11-15: Create a class `Car` with attributes `brand` and `model`. Then, instantiate
an object.
```python
class Car:
def __init__(self, brand, model):
self.brand = brand
self.model = model

def display_info(self):
print(f"Brand: {self.brand}, Model: {self.model}")

# Create an object of Car


car1 = ______("Toyota", "Corolla")
car1.____()
```
Answers: `Car`, `display_info`

16-20: Implement polymorphism by creating a base class `Shape` and two derived
classes `Circle` and `Rectangle` that override a `calculate_area()` method.
```python
class Shape:
def calculate_area(self):
pass

class Circle(Shape):
def __init__(self, radius):
self.radius = radius

def calculate_area(self):
return 3.14 * self.radius ** 2

class Rectangle(Shape):
def __init__(self, width, height):
self.width = width
self.height = height

def ______():
return self.width * self.height

circle1 = Circle(5)
rect1 = Rectangle(4, 6)

print("Circle Area:", circle1.calculate_area())


print("Rectangle Area:", rect1._____())
```
Answers: `calculate_area`, `calculate_area`

#### TRUE OR FALSE:


Encircle TRUE if the statement is correct, otherwise encircle FALSE.

21. Inheritance allows a child class to access methods from a parent class. (TRUE /
FALSE)
22. Abstraction means exposing all details of an object to the user. (TRUE / FALSE)
23. Encapsulation helps protect an object's data from being modified directly.
(TRUE / FALSE)
24. `self` is an optional keyword in class methods. (TRUE / FALSE)
25. Polymorphism allows a method to have the same name but different
implementations in different classes. (TRUE / FALSE)

#### PROBLEM SOLVING:


26-30: Create a class `Employee` with attributes `name` and `salary`. Then, create
a subclass `Manager` that inherits `Employee` and adds a new attribute
`department`.
Write a method in `Manager` to display details.

```python
class Employee:
def __init__(self, name, salary):
self.name = name
self.salary = salary

def display_info(self):
print(f"Name: {self.name}, Salary: {self.salary}")

class Manager(Employee):
def __init__(self, name, salary, department):
super().__init__(name, salary)
self.department = department

def display_manager_info(self):
print(f"Department: {self.department}")

manager1 = Manager("Alice", 50000, "IT")


manager1.display_info()
manager1.________()
```
Answer: `display_manager_info`

You might also like