File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

assignment operator

 
jaysingh solanki
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
code:
class Test
{
int i=4;
i+=5;//line 1
public Test()
{
System.out.println(i);
}
public static void main(String arg[])
{
Test t=new Test();

}
}
My question is why line one gives compile time error
identifier exp.
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"i" is an instance variable (since you don't see the keyword static anywhere).
Consequently, trying to initialize it at the static (class) level will result in an error. If you are trying to make "i" a class-level variable, use the static keyword and place their initiailization in a static { ... } block. Otherwise, "i" is an instance variables and need to be initialized in a constructor, not at Line 1 as it is now.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic