014-001-007

Multi-level Inheritance Implementation

Hard

Problem Description

Multi-level Inheritance Implementation

In this problem, you will create a program that implements a 3-level inheritance hierarchy (Animal → Mammal → Dog), reads an integer from standard input, creates the corresponding instance, and calls all available methods.

Learning Objective: Understand and implement inheritance relationships across multiple levels

Overview

Implement a 3-level inheritance hierarchy (Animal -> Mammal -> Dog). Read an integer (1-3) from standard input, create the corresponding instance, and call all methods available to that class.

Specifications

  • Animal class: eat() method (outputs "Eating...")
  • Mammal class extends Animal: breathe() method (outputs "Breathing...")
  • Dog class extends Mammal: bark() method (outputs "Barking!")
  • In the Main class, read an integer and process as follows:
    • 1: Create an Animal instance and call eat()
    • 2: Create a Mammal instance and call eat() and breathe()
    • 3: Create a Dog instance and call eat(), breathe(), and bark()

Input

Integer (1-3)

Output

When input is 1:

Eating...

When input is 2:

Eating...
Breathing...

When input is 3:

Eating...
Breathing...
Barking!

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up