017-005-010
Combining Class Inheritance with Interface Implementation
Medium
Problem Description
Combining Class Inheritance with Interface Implementation
Learning Objective: Understand how to inherit from a class and implement an interface simultaneously
Overview
Create a Dog class that extends Animal class and implements Trainable interface.
Specifications
Animalclass: hasString namefield andvoid eat()methodeat()outputs "[name] is eating"
Trainableinterface: hasvoid train()methodDogclass: extends Animal and implements Trainable- Constructor receives name
train()outputs "[name] is being trained"
- In
main, create a Dog named "Buddy" and call eat() and train()
Output Format
Buddy is eating
Buddy is being trained
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
