Question
class Output {
public static void main(String args[])
{
int x , y = 1;
x = 10;
if (x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}
What is the output of this program?
class Output {
public static void main(String args[])
{
int x , y = 1;
x = 10;
if (x != 10 && x / 0 == 0)
System.out.println(y);
else
System.out.println(++y);
}
}
Answer: Option B
Was this answer helpful ?
Operator short circuit and, &&, skips evaluating right hand
operand if left hand operand is false thus
division by zero in if
condition does not give an error.
output:
$ javac Output.java
$ java Output
2
Was this answer helpful ?
Submit Solution