Back to slide -- Keyboard shortcut: 'u'              StackMultipleInheritance-0.java - Skitse af FixedStack som kan friste til multiple nedarvning (kan ikke oversættes).Lecture 8 - slide 14 : 26
Program 1

class FixedStack extends Stack,
                 extends Array {
  private int topIndex;

  public FixedStack(){
    // initialize Array aspect somehow
    topIndex = 0;
  }

  public boolean full(){
    return(topIndex >=  maxSize());
  }

  public boolean empty(){
    return(topIndex <=  0);
  }
    
  public void push(Object el){
    if (! full()){  
      put(topIndex, el);
      topIndex = topIndex + 1;
    }
  }
     
  public void pop(){
    if (! empty()){
      topIndex = topIndex - 1;
    }
  }

  public Object top(){
    if (!empty()){
      return (at(topIndex - 1));
    } 
    else return (null);
  }
 
  private String stackContents(){
    StringBuffer st = new StringBuffer();
    for (int i = 0; i < topIndex; i++){
      st.append(at(i).toString());
      st.append(".");
    }
      
    return (st.toString());
  }

  public String toString(){
    return("Stack: " + stackContents());
  }
} // end FixedStack