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
- Define
abstract void speak()inAnimalabstract class - Define a concrete method
describe()inAnimalthat printsI am an animal. Dogclass extendsAnimaland implementsspeak()to printWoof!- In main, create a
Dogobject and call bothdescribe()andspeak()
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