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);
}
}
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
Join The Discussion
Comments ( 2 )
Related Questions on Operators
&& 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).
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.