• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can resolve symbol ???

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

hope that helps
Dave
SCJP
 
I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic