-
Notifications
You must be signed in to change notification settings - Fork 7
/
IfTest3.java
28 lines (23 loc) · 908 Bytes
/
IfTest3.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package chapter9;
/*Create an interface variable and access stacks through it */
public class IfTest3 {
public static void main(String[] args) {
IntStack mystack; //Create an interface reference variable
DynStack ds = new DynStack(5);
FixedStack fs = new FixedStack(8);
mystack = ds; //load dynamic stack
//push some numbers onto the stack
for (int i = 0; i < 12; i++) mystack.push(i);
mystack = fs; //load fixed stack
//push some numbers onto the stack
for (int i = 0; i < 8; i++) mystack.push(i);
mystack = ds;
System.out.println("Values in dynamic stack ");
for (int i = 0; i < 12; i++)
System.out.println(mystack.pop());
mystack = fs;
System.out.println("Values in fixed stack");
for (int i = 0; i < 8; i++)
System.out.println(mystack.pop());
}
}