A

Admin • 828.03K Points
Coach

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
  • Correct Answer - Option(B)
  • Views: 6
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
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.

Be the first to start discuss.