LearnFrenzy
Sign in Take a free test

Inheritance and Polymorphism · Find the Error · Question 2

Error: parent attributes never initialised Answer, explanation & discussion

  • Find the error
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

The program below stops with an error. Which statement correctly describes the problem?

main.py
class Employee:
    def __init__(self, name):
        self.name = name

class Manager(Employee):
    def __init__(self, name, team):
        self.team = team

m = Manager("Asha", ["Ravi"])
print(m.name, m.team)
  • A It prints Asha ['Ravi']
  • B TypeError
  • C AttributeError: Manager.__init__ never calls super().__init__(name), so name is never set Correct
  • D NameError
Correct Answer: Option C

Add super().__init__(name) as the first line of Manager.__init__.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links