Combining competing default implementations

A Java application combines a saved display name with a current display name. The unrelated interfaces below both provide label(), so the implementing class explicitly combines their results.


Java
interface OfflineName {
    default String label() {
        return "saved";
    }
}

interface LiveName {
    default String label() {
        return "current";
    }
}

class CombinedName implements OfflineName, LiveName {
    @Override
    VISIBILITY String label() {
        return FIRST.super.label()
            + "/" + SECOND.super.label();
    }
}


VISIBILITY, FIRST, and SECOND are placeholders. Replace each with one Java keyword or interface name so that the class compiles and new CombinedName().label() returns exactly "saved/current". Preserve all other code.


Replace VISIBILITY with , FIRST with , and SECOND with .

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Interfaces Questions: