016-002-006
Abstract Class: Concrete Methods
Medium
Problem Description
Abstract Class: Concrete Methods
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...")
- Define abstract method
- Dog class: Inherit from Animal,
makeSound()outputs "Woof!" - In Main class, create Dog object and call both
makeSound()andsleep()
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?
