Bird
Raised Fist0

Consider this code:

hard🚀 Application Q9 of Q15
Python - Object-Oriented Programming Foundations
Consider this code:
class Employee:
    def __init__(self, name, salary):
        self.name = name
        self.salary = salary

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

m = Manager("John", 5000, "Sales")
print(m.name, m.salary, m.department)

Which OOP principles are demonstrated here?
AInheritance and encapsulation
BInheritance and constructor chaining
CPolymorphism and abstraction
DEncapsulation and polymorphism
Step-by-Step Solution
Solution:
  1. Step 1: Identify inheritance

    Manager inherits from Employee, so inheritance is used.
  2. Step 2: Identify constructor chaining

    Manager calls super().__init__ to initialize Employee attributes, showing constructor chaining.
  3. Final Answer:

    Inheritance and constructor chaining -> Option B
  4. Quick Check:

    Inheritance + super() call = constructor chaining [OK]
Quick Trick: super() calls parent constructor in inheritance [OK]
Common Mistakes:
MISTAKES
  • Confusing polymorphism with inheritance
  • Missing super() call
  • Assuming encapsulation without private data

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes