aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Precedence question!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Precedence question!!!" Watch "Precedence question!!!" New topic
Author

Precedence question!!!

Terence Lin
Greenhorn

Joined: Mar 11, 2003
Posts: 2
I wonder why the || operator is excetuted before && operator..:??
class A {
static boolean a;
static boolean b;
static boolean c;
public static void main (String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}
}
The result is true, false, false.
P.S This question is from Dan's mock exam, they are really helpful, thanks, Dan.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Welcome to Javaranch, a friendly place for Java greenhorns
Please check out the following discussion which handles the same topic: http://www.coderanch.com/t/240790/java-programmer-SCJP/certification/Simple-precedence
We ain't got many rules 'round these parts, but we do got one. Please change your displayed name to comply with the JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Originally posted by TTT^O^TTT ^O^:

P.S This question is from Dan's mock exam, they are really helpful, thanks, Dan.

You're welcome.
That question seems to be a popular one here at the ranch.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
Originally posted by TTT^O^TTT ^O^:
I wonder why the || operator is excetuted before && operator..:??
class A {
static boolean a;
static boolean b;
static boolean c;
public static void main (String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}
}
The result is true, false, false.
P.S This question is from Dan's mock exam, they are really helpful, thanks, Dan.

The question is not why, it is why not. || and && has equal precedence, so it start from left to right.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Precedence question!!!