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

  1. Define String name field and constructor in Animal class
  2. Animal constructor prints Animal created: <name>
  3. Dog extends Animal, constructor calls super(name)
  4. Dog constructor prints Dog initialized: <name>
  5. 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