


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



public interface InterfaceName { }
public class ClassName implements InterfaceName { }
own type
interface is called a union of classes
the same as any of the interfaces they implement
i.e., an object with no fields i.e., an object with two fields We can translate this definition into a class hierarchy...
implements “contains”
implements “contains” public interface IList {} pulic class MTList implements Ilist { public MTList() {} } public class ConsList implements Ilist { private int first; private IList rest; public ConsList(int first, IList rest) { this.first = first; this.rest = rest; } }
new ConsList(42, new ConsList(43, new ConsList(44, new ConsList(45, new MTList() ) ) ) ) (42, (43, (44, (45, () ) ) ) ) List Creation statement Resulting List Structure To add a method to a union of classes:
type IList, we must add a definition line for a length method to interface IList
we must define the length method in all classes that implement IList: MTList and ConsList
interface, and work our way down...
Does list contain a particular value? /**