1. Home
  2. Computer Science MCQs
  3. JAVA
  4. String s = "Hi"; s.concat("!"); What is the value of s…

Added 2 Nov 2026

String s = "Hi"; s.concat("!"); What is the value of s after these statements?

  1. "Hi" Correct answer
  2. "!"
  3. "Hi!"
  4. null

Correct answer

A. "Hi"

15 views

MCQSEXAM

Explanation

Java Strings are immutable, so concat() returns a new String and leaves s unchanged. The result is lost because it was never assigned. Writing s = s.concat("!") would give "Hi!".

Reference

Asked in: NTS, OCA Java, Technical Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More JAVA MCQs

Practise all JAVA MCQs

Similar MCQs