I'm reading Data Structures by Koffman and Wolfgang and, in their implementation of the ArrayList, they initialize a data field outside of the constructor, and then give it a different value in the constructor.
public class KWArrayList {
private static final int INITIAL_CAPACITY = 10;
private int capacity = 0;
public KWArrayList() {
capacity = INITIAL_CAPACITY;
}
}
Why do they initialize capacity
to 0
outside of the constructor and then give it a different value in the constructor?