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 Animal:
def speak(self): return 'Animal sound'
class Dog(Animal):
def speak(self): return 'Dog barks'
print(Dog().speak())
  1. Dog barks Correct answer
  2. Animal sound
  3. Error
  4. None

Correct answer

A. Dog barks

MCQSEXAM

Explanation

A child class overrides a parent method by defining one with the same name.

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 A? 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