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
Animalclass:speciesfield,Animal(String species)constructorPetclass: extendsAnimal, addsnamefield,Pet(String species, String name)constructorDogclass: extendsPet, addsbreedfield,Dog(String name, String breed)constructorDogconstructor callssuper("Dog", name)to initializePet- 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