/* List subclass that accesses last element. */ import geneseo.cs.sc.List; public class ListWithLast extends List { public Object last () { // Precondition: list is not empty if ( ! this.getRest().isEmpty() ) return ((ListWithLast)this.getRest()).last(); else return this.getFirst(); } public List makeNewList() { return new ListWithLast(); } public static void main(String args[]) { ListWithLast l = new ListWithLast(); l.addItem( "Hello" ); l.addItem( "World" ); System.out.println( l.last() ); } }