Past exam of the mathematics course of the University of Cambridge 2006 ia Paper 5 9 e Solution Created 2026-09-24 Updated 2026-10-14
A collections library can specify a
List<E> Java interface, with different implementations such as ArrayList<E> and LinkedList<E>. A method accepting List<E> can iterate or access elements according to the documented list contract without requiring one particular storage representation. Each implementation may also extend its own appropriate class superclass.The benefit is separating a usable contract from its implementation. A parameter restricted to a concrete
ArrayList<E> would exclude a linked list implementation and unnecessarily expose the storage choice. Requiring all providers to extend one concrete class would couple them to its implementation and consume Java's single class-inheritance relationship. Interfaces permit multiple implemented contracts, though clients must rely on the stated contract rather than assuming every optional operation is supported or has the same time complexity.