










































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











































(fields).
A Class Involves at least 2 People
easy to use.
implemented. He only wants to know the
operations that it can carry out (its interface ).
public class ClassName { Fields // variables used by all methods
Constructor(s) // method(s) that initialize an object
Methods (functions) }
public class Stack { private int store[]; private int max_len; private int top;
// all methods can use fields }
private int top;
visibility type^ variable name
// Stack.java // Written by the Stack implementor
public class Stack { private int store[]; // hidden data private int max_len; private int top;
public Stack(int size) // visible method { store = new int[size]; max_len = size-1; top = -1; } :
public boolean pop() { if (top == -1) return false; top--; return true; }
public int topOf() { return store[top]; }
public boolean isEmpty() { return (top == -1); }
} // end of Stack.java
$ javac Stack.java
$ javac TestStack.java
$ java TestStack Top value is 42
though the methods are stored in the class.