014-001-006

Basic Class Inheritance

Easy

Problem Description

Basic class inheritance

In this problem, you will create a program that defines an Animal parent class with a name field and a makeSound() method, extends it with a Dog child class using the extends keyword, and reads a dog's name via Scanner to call the inherited method.

Learning Objective: Understand the basics of class inheritance using the extends keyword and constructor chaining with super

Overview

Create a child class (Dog) that inherits from a parent class (Animal), read a dog's name via Scanner, and call the inherited method.

Specifications

  • Define a name field and constructor Animal(String name) in the Animal class
  • Define makeSound() method (outputs "{name} says: Some sound")
  • Dog class extends Animal class with constructor Dog(String name) (calls super(name))
  • In Main class, use Scanner to read a dog's name (1 line), create a Dog instance, and call makeSound()

Input Format

Dog's name (1 line)

Output Format

{name} says: Some sound

Input/Output Example

Input: Rex
Output: Rex says: Some sound

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