File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes = operator 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 "= operator" Watch "= operator" New topic

= operator

Anju sethi
Ranch Hand

Joined: Dec 26, 2005
Posts: 91
A very basic Question.

//code in a main
int x;
int y[] = {1, 2};
int c =0;
x = y[0] = c;//one
System.out.println(x + "" + y[0] + y[1]); //o/p is 1 0 2

I am a bit confused in whether the statement //one will be evaluated left to right or right to left. As per rule = operator has right associatity, thus output should be 0 0 2 unlike what is comming.

can anyone explain why is it so?

thanks,<br />Anju Sethi
Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Dear Anju,

After copy, paste and run your code in my netBeans IDE the output is 002.

It's supposed to be correct, isn't it ?

Are you sure you're running the final compiled version of the class ?

"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
Anju sethi
Ranch Hand

Joined: Dec 26, 2005
Posts: 91
yes..just nw checked. i was running old class file.
I agree. Here's the link:
subject: = operator
jQuery in Action, 3rd edition