What will be the output of the following java program? class Example
What will be the output of the following java program?
class Example
{
public static void main(String args[ ])
{
int a = 50;
double b = 50.1;
boolean x = (a == b);
System.out.println(x);
}
}
Show answerHide answer
Correct answer: (A) Compilation error
Explanation
Note: the answer key gives (A), but the code compiles. In a == b the int is widened to double, and 50.0 == 50.1 is false, so the program prints "false" (option B).