Interface Inheritance
Intro to Interface Inheritance Examples of Interface Inheritance
Useful Interface Inheritance
Home
As an example, two interfaces can be declared:

public interface Edible {
float numCalories();
}
public interface Cooked {
float getTemp();
}

A class that inherits both of these interfaces can be declared as:

public class TVDinner implements Edible, Cooked {
public TVDinner(float cal, boolean cooked, float cTemp, float rTemp)
  �
}
public float numCalories() {
  return calories;
}
public float getTemp() {
  if(this.isCooked == �true�)
   return cookedTemp;
  else
   return rawTemp;
}

private float calories;
private boolean isCooked;
private float cookedTemp, rawTemp;
}

This example shows how inheritance is accomplished using interfaces.  Because an interface is not a class, multiple inheritance in Java is accomplished using interfaces.  As this example demonstrates, a single concrete class, TVDinner, can have the properties of being edible and cooked.  If Edible and Cooked were abstract classes, it would not be possible for TVDinner to take on the properties of both.  Notice how TVDinner provides implementations for the methods contained in both interfaces.
Hosted by www.Geocities.ws

1