πŸ“Š JAVA
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
πŸ’¬ Discuss
βœ… Correct Answer: (B) Hello, null!

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!”.

Explanation by: Pushkar
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!”.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
195
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Pushkar
Publisher
πŸ“ˆ
80%
Success Rate