Declaring Arrays
Arrays must be declared like variables. When declaring an array, you list the data type, followed by a set of square brackets [], followed by the identifier name.
Example:
int[] ages; or int ages[];
After Declaring, create the array and specify it's length with a constructor statement. This process in java is call instantiation. In order to instantiate an object, use a constructor.
int ages[];
//you declare an array with data type int and identifier ages
ages = new int [100]
//you declared that ages should contain 100 slots.
or you can put-up the two code lines together just like this:
int ages[] = new int [100];
No comments:
Post a Comment