Question: I have a stack interface and a class which implements the methods in the interface (`push`, `pop`, `isEmpty` and `isFull`).

I'm having trouble displaying the content of the Stack. Here is my main class.

```
    StackInterface si = new MyStack();
    System.out.println("Stack is empty: "+si.isEmpty());

    si.push("Hello");
    si.push("Adam");
    si.push("Horrigan");
    si.isEmpty();
    si.pop();
    si.isFull();

    System.out.println(si);

```

The output is: 

```
Stack is empty: true
stack.MyStack@15db9742

```

I'm wondering, how come the content of the stack isn't output? 

Edit, here is the MyStack class.

```
public class MyStack implements StackInterface {

    public ArrayList<String> theStack;

    public MyStack() {
        theStack = new ArrayList<String>();
    }

    public boolean isEmpty() {
        return theStack.isEmpty();
    }

    public boolean isFull() {
        return false;
    }

    public void push(Object newItem) {
        theStack.add((String) newItem);
    }

    public Object pop() {
        if (!(theStack.isEmpty())) {
            return theStack.remove(0);
        } else {
            return null;
        }
    }

}

```

Answer: 
You should override `toString` in your `MyStack` class in order for it to be displayed as you wish. `MyStack@15db9742` is what the default implementation of `Object`'s `toString` will return.

For example:

```
@Override
public String toString ()
{
    return theStack.toString();
}

```
By calling `System.out.println(si)` indirectly the Stack's `toString()` method is called. Probably this method isn't overwritten by the Stack class, that's why the `toString` method of Object is called. This just prints the object's class and address (`stack.MyStack@15db9742`).

The solution is to overwrite the `toString` method and make an appropriate implementation that returns the desired String.