class Stack
{
Object array[]; //array of Object
: //implementing Stack
:
void push(Object o)
:
:
Object pop()
:
:
}
Stack s;
String x;
s.push(x);
Stack s = new Stack();
String x;
:
:
s.push(x);
:
:
x = s.pop();
When we remove an object, we may need to
"cast"
it to the right type to let the compiler know what is up.
(String)s.pop()
target type of cast
x = (String)s.pop();
String -> Object "Up" cast automatic
Object -> String "Down" cast requires explicit cast