import java.util.Arrays; public class showArrayDeclarations { private Loc[] l1; private Loc[] l2 = new Loc[10]; public class Loc { int x; } public static void main (String[] args) { showArrayDeclarations sa = new showArrayDeclarations(); //The following statement creates an array of type Location //Each entry in the array is set to null sa.l1 = new Loc[10]; System.out.println(Arrays.toString (sa.l1)); //If I wanted to fill the array with actual Location objects //I need to do the following: for (int i=0; i<10; i++) sa.l1[i] = sa.new Loc(); //If I want to set an individual element to a Loc object, //I can do the following (note: the sa.new is necessary //because I defined Loc as a class within a class. If //Loc was in a separate file, only new be necessary): Loc l = sa.new Loc(); sa.l2[0] = l; //Now, both locations point to the same object: System.out.println ("\n" + l + " " + sa.l2[0]); //If I set an instance variable in the object, both references will //see the change l.x = 0; System.out.println ("\nInitially, l2[0] = " + sa.l2[0].x); l.x = 20; System.out.println ("I've set l, l2[0] = " + sa.l2[0].x); } }