Super with method parameters

Viewed 352

I came across this code and am trying to understand what super is doing here:

import java.util.Stack;

public class StackWithMax extends Stack<Integer> {

Stack<Integer> s2;

public StackWithMax() {
    s2 = new Stack<Integer>();      
}

public void push(int value){
    if (value >= max()) {
        s2.push(value);
    }
    super.push(value);
}

public Integer pop() {
    int value = super.pop();
    if (value == max()) {
        s2.pop();           
    }
    return value;
}

public int max() {
    if (s2.isEmpty()) {
        return Integer.MIN_VALUE;
    } else {
        return s2.peek();
    }
  }
} 

When super.push(value) is called, what object is being modified?

What is the difference here between calling s2.push(value) and super.push(value), since super refers to a Stack<Integer> and s2 is a Stack<Integer>?

2 Answers
Related