Logical AND &&
has higher precedence than logical OR ||
.
This is simple java code http://ideone.com/KWUOla
import java.util.*;
import java.lang.*;
import java.io.*;
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
if( A() || B() && C() && D() ){
System.out.println("done...");
}
}
public static boolean A(){
System.out.println("This is class A");
return true;
}
public static boolean B(){
System.out.println("This is class B");
return true;
}
public static boolean C(){
System.out.println("This is class C");
return true;
}
public static boolean D(){
System.out.println("This is class D");
return true;
}
}
In this program function A()
is completing first then OR is evaluated and since the left operand is true the if condition is satisfied.
But as per the precedence table all logical AND &&
should be evaluated before the evaluation of logical OR ||
.
Does Java have the same priority for logical AND &&
and logical OR ||
? If not, please clarify the precedence order between logical AND &&
and logical OR ||
.