top top new item pushed on stack top top top two items popped from stack figure operation of the stackx class methods we've left the responsibility for handling such errors up to the class user the user should always check to be sure the stack is not full before inserting an itemif!thestack isfull(insert(item)else system out print("can' insertstack is full")in the interest of simplicitywe've left this code out of the main(routine (and anywayin this simple programwe know the stack isn' full because it has just been initializedwe do include the check for an empty stack when main(calls pop(many stack classes check for these errors internallyin the push(and pop(methods this is the preferred approach in javaa good solution for stack class that discovers such errors is to throw an exceptionwhich can then be caught and processed by the class user