permaculture playing cards
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can resolve symbol ??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "can resolve symbol ???" Watch "can resolve symbol ???" New topic

can resolve symbol ???

Mateen Nasir
Ranch Hand

Joined: Aug 01, 2001
Posts: 33
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 <identifier> expected
i = 2039;
^ 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
Rehan Malik
Ranch Hand

Joined: Jul 09, 2001
Posts: 76
I believe this is because you cannot assign another value to the variable OUTSIDE of a method.
It works within the method but not outside.

Rehan Malik
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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:

hope that helps

I agree. Here's the link:
subject: can resolve symbol ???
It's not a secret anymore!