Java Test Automation / Quiz

String Values and References

Predict the output of immutable String operations, reference comparisons, and mutable builders in test utilities.

Difficulty
Easy
Format
Quiz
Points
100
Estimate
6 min

// MISSION BRIEF

Your Mission

String bugs often hide in tiny test-data helpers. Read executable fragments, predict their values and reference relationships, and choose the construction that avoids both lost transformations and needless temporary objects.

// FIRST CONTACT

Battle teaser

What does this test print? String status = "draft"; status.concat("-final"); System.out.println(status);

  1. Adraft, because concat returns a new String and the returned reference was not assigned
  2. Bnull, because concat consumes the original
  3. Cdraft-final, because concat mutates status
  4. DIt fails to compile because String has no concat method
Answers, scoring, hints, and the full battle stay sealed.

// SKILL TAGS

java-stringsimmutabilitystringbuilderjava-testing