What will be the output of the below code snippet? public class Quiz1{ public static void main(String args[]) { System.out.print("H" + "a"); System.out.print('H' + 'a'); } }

  1. HaHa

  2. Ha169

  3. Ha Ha

  4. 169Ha


Correct Option: B

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) HaHa - This option is incorrect because the code snippet contains two print statements. The first print statement prints "Ha" as a string concatenation of "H" and "a". The second print statement, however, does not produce the same result.

Option B) Ha169 - This option is correct. The first print statement concatenates "H" and "a" as a string, resulting in "Ha". The second print statement performs addition on the ASCII values of the characters 'H' and 'a', which are 72 and 97, respectively. The sum of these ASCII values is 169, which is then printed.

Option C) Ha Ha - This option is incorrect because there is no space character (represented by " ") in the code snippet. The output will not contain a space between "Ha" and "Ha".

Option D) 169Ha - This option is incorrect because the first print statement concatenates "H" and "a" as a string, resulting in "Ha". The second print statement does not concatenate the strings but performs addition on the ASCII values of the characters 'H' and 'a', resulting in 169. Therefore, the output will start with "Ha", not "169".

The correct answer is B. The output of the code snippet will be "Ha169" because the first print statement concatenates "H" and "a" as a string, and the second print statement performs addition on the ASCII values of 'H' and 'a', resulting in 169.

Find more quizzes: