Bird
0
0

Which of the following is the correct way to create a string variable in Java?

easy📝 Conceptual Q11 of 15
Java - Strings and String Handling
Which of the following is the correct way to create a string variable in Java?
AString greeting = "Hello";
Bstring greeting = 'Hello';
CString greeting = Hello;
DString greeting = "Hello"
Step-by-Step Solution
Solution:
  1. Step 1: Check the data type and quotes

    Java strings use the class String with a capital S and text must be in double quotes.
  2. Step 2: Validate syntax correctness

    String greeting = "Hello"; uses correct capitalization, double quotes, and ends with a semicolon.
  3. Final Answer:

    String greeting = "Hello"; -> Option A
  4. Quick Check:

    String creation uses String and double quotes [OK]
Quick Trick: Use capital S in String and double quotes for text [OK]
Common Mistakes:
  • Using single quotes instead of double quotes
  • Using lowercase 'string' instead of 'String'
  • Missing semicolon at the end

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes