LearnFrenzy
Sign in Take a free test

Inheritance and Polymorphism · Predict the Output · Question 8

A child __init__ without super() Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 8 Back to Exercise

What is the output of the following Python program?

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

class Student(Person):
    def __init__(self, name, roll):
        self.roll = roll

s = Student("Asha", 7)
print(hasattr(s, "roll"), hasattr(s, "name"))
  • A True False Correct
  • B True True
  • C False True
  • D AttributeError
Correct Answer: Option A

Student.__init__ replaced Person.__init__ and never called it, so name was never set.

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