1.

What is the output of the below code and why?

Answer»

public class InterviewBit{ public static void main(String[] args) { System.out.println('b' + 'i' + 't'); }}

“bit” would have been the result PRINTED if the letters were USED in double-quotes (or the string literals). But the QUESTION has the CHARACTER literals (single quotes) being used which is why concatenation wouldn't OCCUR. The corresponding ASCII values of each character would be added and the result of that sum would be printed.
The ASCII values of ‘b’, ‘i’, ‘t’ are:

  • ‘b’ = 98
  • ‘i’ = 105
  • ‘t’ = 116

98 + 105 + 116 = 319

Hence 319 would be printed.



Discussion

No Comment Found