014-002-008
Calling Superclass Constructor with super()
Easy
Problem Description
Calling Superclass constructor with super()
In this problem, you will create a program that defines an Animal class and a Dog subclass, explicitly calls the superclass constructor using super(name), and displays the result to standard output to observe the order of constructor invocations during inheritance.
Learning Objective: Understand how superclass constructors are invoked during inheritance
Overview
Create a Dog class that extends Animal and explicitly calls the superclass constructor with super().
Specifications
- Define
String namefield and constructor inAnimalclass - Animal constructor prints
Animal created: <name> DogextendsAnimal, constructor callssuper(name)- Dog constructor prints
Dog initialized: <name> - Read one line from standard input as the name, then create a Dog object
Input Format
<name>
Output Format
Animal created: <name>
Dog initialized: <name>
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