Top
Previous Next
Java Arrays, Objects, Methods CS 161 - Java

Arrays

Arrays themselves are objects in Java

Even arrays of primitive data types.

int intArray[];

intArray = new int[4];

float[] fnumbers = new float[8];

CSStudent studentArray[] = new CSStudent[10];

Note the last declaration and instantiation of an array of CSStudent objects

Note that array declarations use [], not ()

Question: How many CSStudent objects are created by the declaration?

Since arrays are objects they inherit all the characteristics of java.lang.Object

All array objects also have some other characteristics; i.e., each array has an associated field named length.

Notice it is a field named length, unlike the instance method named length() associated with String objects.


Top
Previous Next
jwd