Q. What is the output of class A: x = 5 class B(A): x = 10 print(B().x)?

A
5
B
10
C
15
D
Error
Solution:

B overrides x, so B().x returns 10, the child’s attribute.

Entri Contact Image

Get Expert Advice for Free: Register for Your Free Consultation Now!