stackinheritancetest.java

来自「金旭亮的java教案」· Java 代码 · 共 43 行

JAVA
43
字号
// StackInheritanceTest.java
// Class StackInheritanceTest

public class StackInheritanceTest {
   public static void main( String args[] )
   {
      StackInheritance objStack = new StackInheritance();  

      // Create objects to store in the stack
      Boolean b = Boolean.TRUE;
      Character c = new Character( '$' );
      Integer i = new Integer( 34567 );
      String s = "hello";

      // Use the push method
      objStack.push( b );
      objStack.print();
      objStack.push( c );
      objStack.print();
      objStack.push( i );
      objStack.print();
      objStack.push( s );
      objStack.print();

      // Use the pop method
      Object removedObj = null;

      try {
         while ( true ) {
            removedObj = objStack.pop();
            System.out.println( removedObj.toString() +
                                " popped" );
            objStack.print();
         }
      }
      catch ( EmptyListException e ) {
         System.err.println( "\n" + e.toString() );
      }
   }
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?