Bird
0
0

Which of the following is the correct way to create a String object in Java?

easy📝 Syntax Q3 of 15
Java - Strings and String Handling
Which of the following is the correct way to create a String object in Java?
AString s = String("hello");
BString s = new String("hello");
CString s = 'hello';
DString s = new string("hello");
Step-by-Step Solution
Solution:
  1. Step 1: Check Java syntax for String creation

    Using new String("hello") is valid syntax to create a String object.
  2. Step 2: Identify incorrect syntax in other options

    String s = String("hello"); misses new keyword; String s = 'hello'; uses single quotes (char); String s = new string("hello"); uses lowercase 'string' which is invalid.
  3. Final Answer:

    String s = new String("hello"); -> Option B
  4. Quick Check:

    Correct String object creation [OK]
Quick Trick: Use new String("text") or "text" literal for strings [OK]
Common Mistakes:
  • Using single quotes for strings
  • Misspelling String with lowercase
  • Omitting new keyword incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes