Question 121Asked in DSSSB TGT Computer Science, 25 Jun 2023, Shift 3 (4:30 PM)

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); } }
  1. ACompilation error
  2. BFalse
  3. CTrue
  4. D50
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).

From DSSSB TGT Computer Science PYQ, 25 Jun 2023, Shift 3 (4:30 PM)

This is question 121 of DSSSB TGT Computer Science PYQ, 25 Jun 2023, Shift 3 (4:30 PM). See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.