Bird
0
0

What is the output of the following code?

medium📝 Predict Output Q4 of 15
Java - Strings and String Handling
What is the output of the following code?
StringBuilder sb = new StringBuilder("Code");
sb.append("Test");
sb.delete(0, 4);
System.out.println(sb);
ACodeTest
BTestCode
CCode
DTest
Step-by-Step Solution
Solution:
  1. Step 1: Append "Test" to "Code"

    After append, sb = "CodeTest".
  2. Step 2: Delete characters from index 0 to 4 (exclusive)

    Deletes "Code", leaving "Test".
  3. Final Answer:

    Test -> Option D
  4. Quick Check:

    Delete + append result = Test [OK]
Quick Trick: delete(start, end) removes substring from start to end-1 [OK]
Common Mistakes:
  • Thinking delete removes from end index inclusive
  • Ignoring append effect
  • Confusing output order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes