017-005-010

Combining Class Inheritance with Interface Implementation

Medium

Problem Description

Combining class inheritance with Interface Implementation

In this problem, you will create a program that defines a Dog class extending Animal and implementing Trainable, then calls each method and displays the results to standard output.

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?

Sign Up