Function call returning array of objects
Hi all,:(hi):
I want to know how to call a function having same return type as that of class which returns array of objects. Problem i'm facing is how to call the function and catch the array.
Here is the code i'm trying to execute:
public class A{
private int x;
private int y;
public A(int j, int k)
{
x=j;
y=k;
}
public A create()
{
A[] obj= new A[5];
for(int n=0;n<5;n++)
{
obj[n]=new A(n,n+1);
}
return obj;
}
public static void main(String args[])
{
A[] ob = new A[5];
ob= create();
System.out.println(ob[0].x+" "+ob[0].y);
}
}
Regards,
ShitalJain.