017-005-008

Resolving Diamond Inheritance Problem

Hard

Problem Description

Resolving Diamond Inheritance Problem

Learning Objective: Understand how to resolve conflicts when multiple interfaces have default methods with the same signature

Overview

Resolve the conflict when two interfaces Walker and Swimmer have default methods move() with the same signature.

Specifications

  • Walker interface: default method move() outputs "Walking"
  • Swimmer interface: default method move() outputs "Swimming"
  • Amphibian class: implements both interfaces
    • Override move() to output "Walking and Swimming"
    • walkOnly() method calls Walker.super.move()
    • swimOnly() method calls Swimmer.super.move()
  • In main, call all three methods

Output Format

Walking and Swimming
Walking
Swimming

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?