Examveda
Examveda

What is the output of the following program?
class Numbers{
        public static void main(String args[]){
                int a=20, b=10;
                if((a < b) && (b++ < 25)){
                        System.out.println("This is any language logic");
                }
                System.out.println(b); 
        }
}

A. 12

B. 11

C. 10

D. Compilation Error

Answer: Option C


This Question Belongs to Java Program >> Operators

Join The Discussion

Comments ( 2 )

  1. Abhishek Saha
    Abhishek Saha :
    6 years ago

    && is a shortcut operator.
    If the left expression to && is false then the expression to the right side of the && operand is ignored(not checked).

  2. Kaushal Bajaj
    Kaushal Bajaj :
    6 years ago

    Since && is a short circuit operator, hence if the left operand is false then the right operand wont be evaluated.
    Since ( a < b ) i.e (20 < 10) is false, the if contains breaks out and b is not incremented and the final value of b remains 10.

Related Questions on Operators