Multiple interface inheritance.

JAVA PRIMER
Objects Don't Polymorph: A Conceptual View of Subtype Polymorphism

Wm. Paul Rogers
Listing 2. Multiple interface inheritance.


public class Base
{
  public String m1()
  { return "Base m1"; }

  public String m2()
  { return "Base m2"; }

  public String m3()
  { return "Base m3"; }
}

public interface Type1
{
  public String m4();
  public String m5();
}

public class Derived1
  extends Base
  implements Type1
{
  public String m1()
  { return "Derived1 m1"; }

  public String m4()
  { return "Derived1 m4"; }

  public String m5()
  { return "Derived1 m5"; }
}

public class Separate
  implements Type1
{

  public String m4()
  { return "Separate m4"; }

  public String m5()
  { return "Separate m5"; }

  public String m6()
  { return "Separate m6"; }
}

// Elided
//
// Attach new Type1 reference to new Derived1 object.
Type1 type1 = new Derived1();

// Send messages m4 and m5 through Type1
// reference. Derived1 object mappings used.
type1.m4();              // "Derived1 m4"
type1.m5();              // "Derived1 m5"

// Attach Type1 reference to new Separate object.
type1 = new Separate();

// Send messages m4 and m5 through Type1
// reference. Separate object mappings used.
type1.m4();           	// "Separate m4"
type1.m5();         	// "Separate m5"