016-002-006

Abstract Class: Concrete Methods

Medium

Problem Description

abstract class: Concrete Methods

In this problem, you will create a program that defines an abstract Animal class and a concrete Dog class, then calls makeSound() and sleep() and displays the results to standard output.

Learning Objective: Understand how to mix concrete and abstract methods in abstract classes

Overview

Create an abstract class representing an Animal and define both concrete and abstract methods. Concrete methods provide common functionality, while abstract methods enforce implementation in subclasses.

Specifications

  • Animal class (abstract):
    • Define abstract method makeSound()
    • Define concrete method sleep() (outputs "Sleeping...")
  • Dog class: Inherit from Animal, makeSound() outputs "Woof!"
  • In Main class, create Dog object and call both makeSound() and sleep()

Output Format

Woof!
Sleeping...

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