User Defined Array
An array is a contiguous block of memory. In this program we have created an array of a user defined class.The initialisation of the array elements is done through the constructor of that class.
/*
http://www.ProbCOMP.com
An array is a contiguous block of memory. In this program we have created an array of a user defined class.
The initialisation of the array elements is done through the constructor of that class.
*/
class Example{
int a;
Example(int a)
{
this.a=a;
}
int getdata()
{
return a;
}
}
public class ArrayObjectsUserDefinedClass{
public static void main(String args[])
{
Example[] array= new Example[4];
array[0] = new Example(1);
array[1] = new Example(2);
array[2] = new Example(3);
array[3] = new Example(4);
for(int i=0;i<4;i++)
{
System.out.println(array[i].getdata());
}
}
}
Download Program


