Program to demonstrate Short Circuiting in Java
public class ShortCircuiting {
public static boolean one(int i){
System.out.println("Evaluated : one");
return i < 2;
}
public static boolean two(int i){
System.out.println("Evaluated : two");
return i < 2;
}
public static boolean three(int i){
System.out.println("Evaluated : three");
return i < 4;
}
public static void main(String[] args) {
boolean b = ( one(1) && two(2) && three(3) );
System.out.println("Evaluation result :" + b);
}
}
Output of the program :
