Question 46Asked in DSSSB TGT Computer Science (Technical), 7 Aug 2021, Shift 3

What is the output of the following JAVA code? String s = "exam" + 9 + 9 + 9;

What is the output of the following JAVA code? String s = "exam" + 9 + 9 + 9; System.out.println(s);
  1. Aexam 27
  2. Bexam: 27
  3. Cexam: 9
  4. Dexam: 999
Show answerHide answer

Correct answer: (D) exam: 999

Explanation

With a String on the left, each + is string concatenation: "exam" + 9 gives "exam9", and so on, giving "exam999". The 9s are not added to 27.

From DSSSB TGT Computer Science PYQ (Technical), 7 Aug 2021, Shift 3

This is question 46 of DSSSB TGT Computer Science PYQ (Technical), 7 Aug 2021, Shift 3. 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.