i have compiled the following code and receive the error given below class ATest { static int i = 2 ; static int [] b = new int[i] ; i = 2039; public static void main( String[] args ) { System.out.println ( " testing" ) ; // 2 } } MESSSAGE FROM COMPILER ATest.java:4: <identifier> expected i = 2039; ^ ATest.java:4: cannot resolve symbol symbol : class i location: class ATest i = 2039; ^ 2 errors I FAIL to understand why the compiler cannot resolve the variablr that i have jsut defined above using the variable inside the method i.e. coping thesame statement that gives the error to location 2 inside main does not give any error I cannot understand why?? can anyone help
Mateen After a variable is declared the only place you can assign a new value is within a block of code. Within a static initializer block (for static variables), an instance initializer block (for instance variables) or in a constructor of method. like this: