`
class under
{
static int[] locations ={2,3,4};//arrays declared with values in class under
}
class understand
{
String c;
public static void main(String[] args)
{
under d=new under();
System.out.println(under.locations[0]);
understand[] u;//next array created created in the main class using //reference//
u = new understand[2];
u[0]=new understand();
u[0].c="ab";
System.out.println(u[0].c);
}
}`
I have the following questions in this code they are:
1.)The first array that I create is of integer type named locations with values inside it.Why do I have make it static in order access it in the main class?
2.)The second concern is the array created in the main class using reference will not be created if i don't name it same as a class. Every time I create using array with reference ,I have to have the same class of it. Why do I need to have a class of the same as the array ? What is the default type of the array created in the main? . The array with reference for example: understand[] array in the main ,if created out the main with references will not be accepted. Can I create a referenced array with out a class of it?
3.)Rather than creating the array using references ,I can directly give values to it then use it accordingly.Why do I need a reference to an array?
Thanks a lot for having attention. Your opinion on this is very valuable to me.It means a lot when my doubts get cleared by the erudite members of Stack overflow.
enter code here