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:
Step 1: Check Java syntax for String creation
Using new String("hello") is valid syntax to create a String object.
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.
Final Answer:
String s = new String("hello"); -> Option B
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
Master "Strings and String Handling" in Java
9 interactive learning modes - each teaches the same concept differently