Bird
0
0

Which of these lines will cause a compilation error in Java?

easy📝 Syntax Q3 of 15
Java - Strings and String Handling
Which of these lines will cause a compilation error in Java?
AString s = "Hello";
BString s = new String("Hello");
CString s = 'Hello';
DString s = "Hello" + " World";
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct string syntax

    Strings must be enclosed in double quotes "", not single quotes ''.
  2. Step 2: Check each option

    String s = 'Hello'; uses single quotes for multiple characters, which is invalid and causes a compilation error.
  3. Final Answer:

    String s = 'Hello'; causes error -> Option C
  4. Quick Check:

    Strings use double quotes "" [OK]
Quick Trick: Use double quotes for strings, single quotes for chars [OK]
Common Mistakes:
  • Using single quotes for strings
  • Confusing char and string literals
  • Missing quotes entirely

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes