Tuesday, 27 November 2018

Java - Logical Vs Short Circuit Operator


Logical and
  It checks the conditions up to last expression, even the first expression is false.
Short circuit and
If first condition is false, returns false without checking remaining expressions.
Example
class TernaryOp
{
   public static void main(String arg[])
         {
              int a=70,b=40;
              String str=((a>=35)&(b>=35))?"Pass": "fail";
              System.out.println("str:"+str);
         }
}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.