Q. What is the output of the following code?

Code:
String name = “John”;
System.out.println(“Hello, ” + name + “!”);
  • (A) Hello, John!
  • (B) Hello, name!
  • (C) Hello, !
  • (D) John
πŸ’¬ Discuss
βœ… Correct Answer: (A) Hello, John!
Explanation: The string concatenation operator (+) combines the string “Hello, ” with the value of the name variable (which is “John”) and the string “!”, resulting in the output “Hello, John!”.
Explanation by: Pushkar
The string concatenation operator (+) combines the string “Hello, ” with the value of the name variable (which is “John”) and the string “!”, resulting in the output “Hello, John!”.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
327
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Pushkar
Publisher
πŸ“ˆ
98%
Success Rate