016-002-007

Abstract and Concrete Methods Together

Easy

Problem Description

Abstract and Concrete Methods Together

In this problem, you will create a program that defines an Animal abstract class with an abstract method speak() and a concrete method describe(), implements speak() in a Dog subclass, and displays the result of calling both methods to standard output.

Learning Objective: Understand that abstract classes can contain both abstract and concrete methods

Overview

Define an Animal abstract class with an abstract method speak() and a concrete method describe(). Create a Dog class that extends Animal and implements speak().

Specifications

  1. Define abstract void speak() in Animal abstract class
  2. Define a concrete method describe() in Animal that prints I am an animal.
  3. Dog class extends Animal and implements speak() to print Woof!
  4. In main, create a Dog object and call both describe() and speak()

Output Format

I am an animal.
Woof!

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