014-002-001

Implicit Default Constructor Call

Easy

Problem Description

Implicit Default constructor Call

In this problem, you will create a program that implements inheritance with Pet as the parent class and Dog as the child class, demonstrating how the parent's default constructor is implicitly called from the child constructor, and displays the result to standard output.

Learning Objective: Understand implicit super() call

Create a pet management system. Define a Pet class with a name field and a default constructor, then implement a Dog class that extends Pet. Read a name from Scanner and pass it to the Dog constructor. Even without an explicit super() call in Dog's constructor, verify that Java automatically invokes the parent's default constructor first.

Input

Line 1: The pet's name (String)

Output

===== Constructor Call Order =====
Pet default constructor called
Dog constructor called
Pet: <name>
=================================

Input Example

Pochi

Output Example

===== Constructor Call Order =====
Pet default constructor called
Dog constructor called
Pet: Pochi
=================================

Test Cases

※ Output examples follow programming industry standards

Normal case
Input:
Luna
Expected Output:
===== Constructor Call Order =====
Pet default constructor called
Dog constructor called
Pet: Luna
=================================
Normal case
Input:
Max
Expected Output:
===== Constructor Call Order =====
Pet default constructor called
Dog constructor called
Pet: Max
=================================

Your Solution

Current Mode: My Code
Pet.java🔒
Dog.java🔒
Solution.java🔒
3/6 ファイル337B
public class Pet {
}
0 B / 5 MB

You have 10 free executions remaining