Inheritance


Interface & Inheritance Examples

Interfaces Inheritance
public interface SorterInterface
{

  // Methods
  
    /**
     * Describes sorting algorithm.
     */
    public String getDescription();
    
    /**
     * Sorts data in ArrayList.
     */
    public void sort(ArrayList data);

}

public abstract class SorterAbstClass
implements SorterInterface
{
  // State: instance variables go here.
    private String description;

  // Constructor

    /**
     * Constructs new object of class.
     */
    public SorterAbstClass(String desc)
    {
        // initialise instance variables
        this.description = desc;
    }

  // Methods
  
    /**
     * Describes sorting algorithm.
     */
    public String getDescription()
    {
        return this.description;
    }

    /**
     * Sorts data in ArrayList.
     */
    public abstract
    void sort(ArrayList data);

}


Alyce Brady, Kalamazoo College