Introduction to OOP | Chapter 19: Container Classes : | next | previous | audio | real | text |
Stack stk = new Stack(); stk.addElement(new Cat()); stk.addElement(new Dog()); // ... adding more values // now do something with Cat values if (stk.peek() instanceof Cat) { // do conversion to Cat Cat aCat = (Cat) stk.pop(); // .. also do something with cat values // now do something with Dog values } else if (stk.peek() instanceof Dog) { // do conversion to Dog Dog aDog = (Dog) stk.pop(); // .. do something with Dog value }