abstract class Dog { protected String name; protected Dog(String name) { this.name = name; } abstract public void bark(); } class Labrador extends Dog { public Labrador(String name) { super(name); } public void bark() { System.out.println(name + ": woof!"); } } class Dalmatian extends Dog { public Dalmatian(String name) { super(name); } public void bark() { System.out.println(name + ": weee-arrr-ooof!"); } } /** Standard singly linked list cell */ class ListCell { private final Object value; private final ListCell next; public ListCell(Object value, ListCell next) { this.value = value; this.next = next; } public Object getValue() { return value; } public ListCell next() { return next; } } public class Kennel { private ListCell dogs; // The head of the list public Kennel(ListCell dogs) { this.dogs = dogs; } public void rollCall() { for (ListCell cell = dogs; cell != null; cell = cell.next()) { Dog d = (Dog)cell.getValue(); d.bark(); } } public static void main(String[] args) { Dog rover = new Labrador("rover"); Dog spots = new Dalmatian("spot"); ListCell dogs = new ListCell(rover, new ListCell(spots, null)); Kennel k = new Kennel(dogs); k.rollCall(); } }