1. Home
  2. Data Science
  3. Python
  4. What is the output of the following Python code snippet?

Added 25 Nov 2026

What is the output of the following Python code snippet?

class A:
def f(self): return 'A'
class B(A):
def f(self): return 'B'
print(B().f())
  1. A
  2. Error
  3. B Correct answer
  4. None

Correct answer

C. B

11 views

MCQSEXAM

Explanation

Overriding with a call to super() combined with a different return shows the child result.

Reference

Asked in: Python Interview OOP

https://docs.python.org/3/tutorial/classes.html

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Python MCQs

Practise all Python MCQs

Similar MCQs