PCPP 32 10x PCPP Certified Professional Python Programmer 1 · Free Practice Question Easy

Question 40

Consider the following class hierarchy in Python:



Given the class hierarchy above, which of the following statements is true?

  • A

    The Animal class inherits from the Mammal class.

  • B

    An instance of the Dog class will have access to the eat() method.

  • C

    The Mammal class has access to the wag_tail() method.

  • D

    The Dog class is a superclass of the Mammal class.

Reveal correct answer

Correct answer: B

A.

In the given class hierarchy, the Animal class is the superclass of the Mammal class. It is the other way around—the Mammal class inherits from the Animal class.

B.

Since the Dog class inherits from the Mammal class, an instance of the Dog class will also inherit the eat() method from the Animal class through the Mammal class. Therefore, an instance of Dog will have access to the eat() method.

C.

The wag_tail() method is defined in the Dog class, not in the Mammal class. Instances of the Mammal class do not have access to the wag_tail() method.

D.

The Dog class is not a superclass of the Mammal class. Instead, the Mammal class is the superclass of the Dog class.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need