CS202 Java-28
Arrays of class type…
lAll arrays of class types must be defined using new (with an exception of the String class….)
•list [] array = new list[size];
lBut, such arrays are actually arrays of references to our objects – not instances!
•(like an array of pointers in C++)
lIf you forget to allocate objects for the elements, you will get an exception
lList [] array = new list[] {new list(1), new list (2), new list(3)};
lOr, do this explicitly with a loop
lUnlike C and C++, Java allows the return type of functions to be an array