// MemoryCell class // Fig 4.21 & 4.22, pg 119
// Object read(
) --> Returns the stored value
// void write(
Object x ) --> x is stored
public class MemoryCell
{
// Public
methods
public Object
read( ) { return storedValue;
}
public void
write( Object x ) { storedValue = x; }
//
Private internal data representation
private
Object storedValue;
}
public class TestMemoryCell
{
public static
void main( String [ ] args )
{
MemoryCell m = new MemoryCell( );
m.write(
"57" );
String
val = (String) m.read( );
System.out.println( "Contents are: " + val );
}
}