| Author |
operator precedence
|
sanjay kumar
Greenhorn
Joined: Aug 29, 2006
Posts: 2
|
|
I am new to scjp preparation group. so first hi to all.. iam not absolutely clear about operator precedence . question: class Sam { static boolean a,b,c,d; public static void main(String arg[]) { d = (a=true) || (b=true) && (c=true); System.out.println(a +","+b+","+c); } } output:true,false,false doubt:&& has higher precedence than || then why || is evaluated first. suggest me a clear guide/tutorial for operator precedence and associativity.
|
 |
Srikanth Basa
Ranch Hand
Joined: Jun 06, 2005
Posts: 241
|
|
So the answer to your question goes as below Evaluate: ((a=true) || ((b=true) && (c=true))); Evaluate: ((true) || ((b=true) && (c=true))); // a=true is executed As it knows true || something is always true (short circuited), the control breaks at this step without executing the further statements for b and c So the result is a=true b=false and c=false
|
 |
wise owen
Ranch Hand
Joined: Feb 02, 2006
Posts: 2023
|
posted

0
|
Java Operator Precedence and Associativity Table What are operator precedence and the order of operand evaluation?
|
 |
 |
|
|
subject: operator precedence
|
|
|