Lecture 2 April 2nd 2014 public class Lecture2 Client you will actually run public class ArrayIntListClient public static void main String args ArrayIntLIst list1 new ArrayIntList list1 elementData 0 23 list1 size list1 add 23 System out println list1 Class Null pointer exception hasn t been properly initalized in this case no constructor public class ArrayIntList private int size encapsulating fields Hiding data away from client private int elementData public ArrayIntList elementData new int 10 0 add 23 23 1 1 add 56 23 56 2 2 add 45 23 56 45 3 Warning size might become greater than 10 public void add int value elementData size value size public void add int index int value for int i size i index i elementData i elementData i 1 elementData index value size public String toString String result Only return this String if there is an array Thus if statement if size 0 result elementData 0 for int i 1 i size i result elementData i result return result
View Full Document