Courseiva
Primitives, Strings and OperatorshardMultiple ChoiceObjective-mapped

1Z0-811 Primitives, Strings and Operators Practice Question

Exhibit

public class StringTest {
    public static void main(String[] args) {
        String s = "Hello";
        s.concat(" World");
        System.out.println(s);
    }
}

Refer to the exhibit. What is the output?

⚠ Common exam trap

Oracle often tests the immutability of `String` by having candidates assume that methods like `concat()` modify the original object, leading them to pick `HelloWorld` instead of recognizing that the result must be assigned to a variable to be retained.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Hello

The code prints 'Hello' because the `String` variable `str` is assigned the value `"Hello"` and then `str.concat("World")` is called. However, `String` objects are immutable in Java, so `concat()` returns a new string without modifying the original `str`. Since the result of `concat()` is not assigned back to `str`, the original `str` remains `"Hello"`, and `System.out.println(str)` outputs `Hello`.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • HelloWorld

    Why it's wrong here

    No concatenation performed.

  • Hello World

    Why it's wrong here

    concat does not modify original.

  • Compilation error

    Why it's wrong here

    Code compiles fine.

  • Hello

    Why this is correct

    String is immutable, s unchanged.

About these practice questions

One of 481 original 1Z0-811 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This 1Z0-811 practice question is part of Courseiva's free Oracle certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 1Z0-811 exam.