I am new to java and trying to learn array in java, so when i executed this
class Example
{
int [] i= new int[2];
i[0]=5; //error in this line. Trying to assign 5 to 1st position of array i.
void m1()
{
System.out.println("i[0]:"+i);
}
public static void main(String args[])
{
Example a=new Example();
a.m1();
}
}
it gives error as ']' expected on line number 4 here.
I know within function it will work only want to know why not like this and is there any solution and if not what is the reason?
Sorry, didn't copy but wrote the program incorrectly...Now its the correct one.