Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

I WANT REASON FOR THIS PROGRAM THROUGH JLS CAN ANY ONE HELP ME  RSS feed

 
LOVENEST
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A
{
int i=10;
public static void main(String[]s)
{
A a=new A();
System.out.println(a.++i);(does not compile)
System.out.println(a.i++); (compiles)
}
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"MURALI'S MIND",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And PLEASE STOP SHOUTING! We can hear you fine when type in mixed case.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And, this doesn't seem to have anything to do with WebLogic, so it's been moved to the Java in General (beginner) forum.
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The value is referenced by a.i. If you want a prefix increment, place the operator before a.i. For example...

[ February 13, 2006: Message edited by: marc weber ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You want JLS? Here's the JLS for ++a.i

Boy, can't you just feel your brain on steroids when you read the JLS? And why can't you write a.++i? The only appropriate syntax rule is the one for FieldAccess, and the expression following the dot can't be a PreIncrementExpression.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!