Question 493 of 481
Valid Ways to Create a String Object in Java
Which TWO of the following are valid ways to create a String?
Quick Answer
The answer is B and E. Option B is correct because using the `new` keyword, as in `new String("Hello")`, explicitly creates a new String object in the heap, which is a perfectly valid way to instantiate a String, even though it bypasses the string constant pool. Option E is correct because a string literal, like `"Hello"`, is the most common and efficient way to create a String object in Java, as it automatically leverages the string constant pool for reuse and memory optimization. On the Oracle Java Foundations 1Z0-811 exam, this question tests your understanding of the two distinct paths for String creation—literal vs. `new`—and often includes traps like using `String s = new` without a constructor argument or confusing String with StringBuilder. A common memory tip: think of the literal as the "pool party" where strings share space, while `new` always throws a private party on the heap.
⚠ Common exam trap
Oracle often tests the distinction between string literals and `new String()`, and the trap here is that candidates may think `String.valueOf("Hello")` creates a new String, when it actually returns the same reference from the pool, making it not a valid 'creation' in the exam's intended sense.
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 = new String("Hello");
It uses the `new` keyword to explicitly create a new String object in the heap, which is a valid way to instantiate a String. Option E is correct because it uses a string literal, which is the most common and efficient way to create a String in Java, leveraging the string constant pool.
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 = 'Hello';
Why it's wrong here
Single quotes for char.
- ✓
String s = new String("Hello");
Why this is correct
Correct.
- ✗
String s = 123;
Why it's wrong here
Cannot assign int to String.
- ✗
String s = String.valueOf("Hello");
Why it's wrong here
Valid method but not a creation syntax; still creates a string but not a direct way.
- ✓
String s = "Hello";
Why this is correct
Correct.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Same concept, more angles
1 more way this is tested on 1Z0-811
These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.
Variation 1. Which two of the following are valid ways to create a String object?
medium- ✓ A.String s = "Hello";
- B.String s = 12345;
- C.String s = (String) new Integer(10);
- ✓ D.String s = new String("Hello");
- E.String s = 'Hello';
Why A: A string literal, which is a valid way to create a String object. Option D uses the String constructor with a string argument, also valid. Option B assigns an integer literal to a String variable, which is not allowed. Option C attempts to cast an Integer object to String, which causes a compile-time error because Integer is not a subclass of String. Option E uses a char literal ('Hello' is invalid because char literals are single characters) and is not assignable to String.
Last reviewed: Jun 30, 2026
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.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.