Oracle Certified Associate Java Se 8 Programmer · Free Practice Question Easy

Question 56

public class StringBuilderTest {

    public static void main(String[] args) {

        StringBuilder sb = new StringBuilder();

        System.out.println(sb.append("A").append("B").append("C").length());

    }

}


What will be the result of compiling and executing StringBuilderTest class?

  • A

    2

  • B

    1

  • C

    3

Reveal correct answer

Correct answer: C

Explanation

Appending three characters ("A", "B", and "C") to the StringBuilder increases its length to 3. Therefore, sb.length() returns 3.

Discussion

Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.

You must be logged in to post a comment.

Preparing For

Your Certification?

255+ certifications
Detailed explanations
Free PDF samples

Has All The Questions You Need