File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes assignment operators 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 "assignment operators" Watch "assignment operators" New topic
Author

assignment operators

jaysingh solanki
Greenhorn

Joined: Nov 11, 2003
Posts: 14
code:
class T
{
public static void main(String arg[])
{
boolean b1=false,b2=false,b3=true;
b1&=true;//line1
b2|=b1; //line2
b3^=b2|=b3;//line3
boolean b4=false | false;//line4
System.out.println(b1+"\n"+b2+"\n"+b3+"\n"+b4);
}
}
output:false
:true
:false
:false
My Question:why line2 is true.If line2 is true
than line4 also true.
H Gokulam
Ranch Hand

Joined: Nov 04, 2003
Posts: 46
Hi,
Line 2 doesn't produce a 'true'. It is line line 3 which is assigning 'true' to b2. Try commenting line 3... value b2 remains false.
or just add
System.out.println(b2);
before line 3.
Hope you got it !!


Harikumar G<br />SCJP 1.4
sanjana narayanan
Ranch Hand

Joined: Nov 25, 2003
Posts: 142
can u tell me how this line b3^=b2|=b3;//line3
is getting executed with b2=true.
-Sanjana
H Gokulam
Ranch Hand

Joined: Nov 04, 2003
Posts: 46
Hi,
can u tell me how this line b3^=b2|=b3;//line3
is getting executed with b2=true.

Assignment operators are evaluated right to left.
b3^=b2|=b3 will be like b3 = b3 ^ (b2 = b2 | b3)
ie: b3 = b3 ^(b2 = false | true) here b2 will be assigned with value 'true'
jaysingh solanki
Greenhorn

Joined: Nov 11, 2003
Posts: 14
Thanks hari now my concept is clear
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: assignment operators
 
Similar Threads
Operator precedence
Boxing query
Please explain boxing conversion
conditional operator precedence
Boolean operators