014-003-011

Multi-Level super() Chain

Hard

Problem Description

Multi-Level super() Chain

In this problem: You will create a program with a 3-level inheritance structure (Animal -> Pet -> Dog) where each constructor uses super() to initialize the parent class in sequence.

Learning Objective: Understand how super() call chains work in multi-level inheritance

Overview

The Animal class manages the species. The Pet class extends Animal and adds a name. The Dog class extends Pet and adds a breed. Each constructor calls super() to initialize its parent, forming a chain.

Specifications

  • Animal class: species field, Animal(String species) constructor
  • Pet class: extends Animal, adds name field, Pet(String species, String name) constructor
  • Dog class: extends Pet, adds breed field, Dog(String name, String breed) constructor
  • Dog constructor calls super("Dog", name) to initialize Pet
  • Print information from each level

Output Format

Species: Dog
Name: Pochi
Breed: Shiba Inu

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