Home / Programming MCQs / JAVA MCQs / Question

P

Pushkar • 380 Points
Valuable

Q. What is the output of the following code?

Code:
String name = null;
System.out.println(“Hello, ” + name + “!”);
(A) Hello, !
(B) Hello, null!
(C) Null Pointer Exception
(D) Compilation Error

Explanation:

When a null reference is concatenated with a string, it is treated as the string “null”. So the output of this code is “Hello, null!”.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.