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

  • Animal class: has String name field and void eat() method
    • eat() outputs "[name] is eating"
  • Trainable interface: has void train() method
  • Dog class: 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?