/* * MyInteger - an integer wrapper, designed for * use with the Testable interface. */ public class MyInteger implements Testable { int data; public MyInteger( int d ) { data = d; } public String toString( ) { return String.valueOf( data ); } public boolean isLessThan( Object x ) { MyInteger m = (MyInteger) x; // cast x to MyInteger return ( data < m.data ); } /* Here are some failed attempts at defining isLessThan() */ /* * The following fails because x is not of type MyInteger, so * we cannot access the data instance variable. */ /* public boolean isLessThan( Object x ) { return ( data < x.data ); } */ /* * The following fails because it fails to implement the * isLessThan() interface, which requires an Object as its * argument. */ /* public boolean isLessThan( MyInteger m ) { return ( data < m.data ); } */ }