• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compound operators  RSS feed

 
Laimonas Oberauskis
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I've run into such problem.



The code won't compile. Same for a += 1 or a++. Why?
 
Stephan van Hulst
Saloon Keeper
Posts: 7987
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is not with what operator you're using, but with where you're putting your code. You can't just have statements inside your class body, they need to be in a method.
 
Yosuf Ibrahim
Ranch Hand
Posts: 128
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Laimonas Oberauskis wrote:Hi, I've run into such problem.



The code won't compile. Same for a += 1 or a++. Why?


Outside the method, you can only declare variables and initialize them, however doing anything to the variable after initializing it has to be inside a method.
 
Paul Clapham
Sheriff
Posts: 22828
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To be picky, a statement has to be in a method or a constructor or an initializer. (There's probably something else I've left out.) But in any case your statement isn't in any of those things, hence the error message.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!