1Z0-811 Primitives, Strings and Operators Practice Question
Which two of the following 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";
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.
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 this is correct
String literal, directly assigned to String variable. This is valid because string literals are instances of String.
- ✗
String s = 12345;
Why it's wrong here
Cannot assign an integer literal to a String variable. Type mismatch.
- ✗
String s = (String) new Integer(10);
Why it's wrong here
Attempts to cast an Integer object to String, which causes a compile-time error because Integer is not a subclass of String.
- ✓
String s = new String("Hello");
Why this is correct
Creating a String object via the String constructor with a string argument. Valid.
- ✗
String s = 'Hello';
Why it's wrong here
Uses a char literal 'Hello', but char literals are single characters, so 'Hello' is invalid and not assignable to String.
Go deeper
Related to this question
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 →
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.