OOP Exam Reviewer
OOP Exam Reviewer
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!")
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}")
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)
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)
```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}")