O'Reilly logo

A Programmer’s Guide to Java® SE 8 Oracle Certified Associate (OCA) by Rolf W Rasmussen, Khalid A Mughal

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix D. Solutions to Programming Exercises

1 Basics of Java Programming

1.1 The printStackElements() method of the PrintableCharStack class does not pop the elements.

// File: CharStack.java public class CharStack {   // Instance variables:   protected char[] stackArray;   // The array implementing the stack.   protected int    topOfStack;   // The top of the stack.   // Static variable   private static int counter;                                      // (1)   // Constructor now increments the counter for each object created.   public CharStack(int capacity) {                                 // (2)     stackArray = new char[capacity];     topOfStack = -1;     counter++;   }   // Instance methods:   public ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required