Question 8
Back to Exercise
What is the output of the following Python program?
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!