ProgrammingHardGATE CS · Product-company placement

What is printed?

What is printed?
class A:
    x = "A"
    def get(self): return self.x
class B(A):
    x = "B"
b = B()
A.x = "A2"
b.x = "inst"
del b.x
print(b.get(), A().get())
  1. A. B A2
  2. B. inst A2
  3. C. A2 A2
  4. D. B A

Correct answer: A. B A2

Attribute lookup goes instance dict, then class MRO. After deleting the instance attribute, b.x finds B.x = 'B'. A().x finds A.x, rebound to 'A2'.

More Python Programming questions

Exams that ask this topic