Single Choice Easy

QPredict the output of the following code snippet: String P = "20", Q ="22";

 int a = Integer.parseInt(P);
int b = Integer.valueOf(Q);
System.out.println(a+""+b);

ID: #19885 Inheritance in Java (IS-A) 110 views
Question Info
#19885Q ID
EasyDifficulty
Inheritance in Java (IS-A)Topic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A 20
  • B 20 22
  • C 2220
  • D 22
Correct Answer

Explanation

The correct answer is:

(c) 2220

Explanation:

  1. int a = Integer.parseInt(P); - Converts the string "20" to an integer and assigns it to variable a.
  2. int b = Integer.valueOf(Q); - Converts the string "22" to an integer and assigns it to variable b.
  3. System.out.println(a + "" + b); - Concatenates the values of a and b as strings and prints the result. In this case, it prints "20" + "22", resulting in "2022".

Share This Question

Challenge a friend or share with your study group.