Courseiva
Java Basics and SyntaxeasyMultiple SelectObjective-mapped

1Z0-811 Java Basics and Syntax Practice Question

Which TWO are valid ways to create a String object?

⚠ Common exam trap

Oracle often tests the distinction between string literals and the new keyword, and the trap here is that candidates may think any use of new is invalid or that a null reference counts as creating an object, but the exam expects you to know that only literals and the String constructor with a String argument are valid ways to create a String object.

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

String s = "hello";

Using a string literal ("hello") creates a String object automatically via the JVM's string constant pool, which is a standard and valid way. Option E is correct because the String constructor new String(String) takes another String as an argument, here "hello", which is valid. Option A is incorrect because null is not an object; it is a reference that does not point to any object. Option B is incorrect because the String constructor expects a String or other char sequence, not an int literal. Option D is incorrect because single quotes denote a char literal, not a String.

Answer analysis

Option-by-option breakdown

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

  • String s = null;

    Why it's wrong here

    Declares reference but does not create an object.

  • String s = new String(10);

    Why it's wrong here

    No such constructor; expects String or char[] etc.

  • String s = "hello";

    Why this is correct

    String literal creates a String object.

  • String s = 'hello';

    Why it's wrong here

    Single quotes are for char, not String.

  • String s = new String("hello");

    Why this is correct

    Explicit constructor call creates new object.

About these practice questions

Courseiva writes every 1Z0-811 question from scratch — 481 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.