Lec6 Mcas2130
Lec6 Mcas2130
UNIT II
Class and Methods
•
One-Dimensional Arrays :
The general form of a one-dimensional array declaration is
type var-name[]; OR type[] var-name; An array declaration has two components: the type and the name. type declares
the element type of the array. The element type determines the data type of each element that comprises the array.
Like array of int type, we can also create an array of other primitive data types like char, float, double..etc or user
defined data type(objects of a class).Thus, the element type for the array determines what type of data the array will
hold.
Example:
• // of unknown type Although the above first declaration establishes the fact
that intArray is an array variable, no array actually exists. It simply tells to the
compiler that this(intArray) variable will hold an array of the integer type. To
link intArray with an actual, physical array of integers, you must allocate one
using new and assign it to intArray.
• Arrays of Objects
• An array of objects is created just like an array of primitive type data items in
the following way.
• Student[] arr = new Student[7]; //student is a user-defined class
• Student[] arr = new Student[5];
References: