Courseiva
Java Basics and SyntaxhardMultiple ChoiceObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

Given the code: String s1 = "Java"; String s2 = new String("Java"); if (s1 == s2) { System.out.print("Equal"); } else { System.out.print("Not Equal"); } What is the output?

⚠ Common exam trap

Oracle often tests the difference between reference equality (==) and value equality (.equals()) with strings, trapping candidates who assume == compares the actual text content.

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

Not Equal

The == operator compares object references, not the actual string content. s1 is a string literal stored in the string pool, while s2 is a new String object created on the heap, so they refer to different memory locations, making the comparison false and printing 'Not Equal'.

Answer analysis

Option-by-option breakdown

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

  • Runtime error

    Why it's wrong here

    No runtime error.

  • Compilation error

    Why it's wrong here

    Code compiles.

  • Equal

    Why it's wrong here

    == compares references, not content.

  • Not Equal

    Why this is correct

    s1 is interned, s2 is a new object.

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.