Choosing how to earn college credit? CLEP vs AP guide
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 3: Class Creation
Start Practice TestPractice Test
About Exam
hard

Immutable String Transformation

Mark
< Prev
Next >

A method accepts a String parameter and attempts to modify it. Identify the output after the method completes its operation.

What is printed when the following Java program is compiled and run?

class TextHelper {

    public String modify(String s) {
        s = s + "X";
        return s;
    }
}

public class QuestionTrace {

    public static void main(String[] args) {
        String s = "A";
        TextHelper t = new TextHelper();
        String r = t.modify(s);
        System.out.print(s + r);
    }
}
A

AXAX

B

AXA

C

AAX

D

AA

Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Instagram: @_apfive_|Privacy Policy|