LearnFrenzy
Sign in Take a free test

Inheritance and Polymorphism · Find the Error · Question 3

Error: super().__init__() without the required argument Answer, explanation & discussion

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

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

main.py
class Shape:
    def __init__(self, colour):
        self.colour = colour

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

c = Circle(5)
  • A TypeError: Shape.__init__ needs colour, but super().__init__() passes nothing Correct
  • B It creates the circle with colour None
  • C AttributeError
  • D RecursionError
Correct Answer: Option A

super().__init__ follows the parent's signature: pass colour along, e.g. def __init__(self, radius, colour="red").

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