Bird
0
0

Which of the following is the correct way to declare a reference variable for a String in Java?

easy📝 Syntax Q12 of 15
Java - Memory Management Basics
Which of the following is the correct way to declare a reference variable for a String in Java?
Aint s = new String();
Bboolean s = new String();
CString s = 10;
DString s = new String();
Step-by-Step Solution
Solution:
  1. Step 1: Check variable type and assignment

    String is a reference type, so it can be assigned with new String() to create a new object.
  2. Step 2: Verify type compatibility

    int and boolean are primitive types and cannot be assigned a String object.
  3. Final Answer:

    String s = new String(); -> Option D
  4. Quick Check:

    Reference declaration matches object creation [OK]
Quick Trick: Reference types use 'new' with matching type [OK]
Common Mistakes:
  • Assigning objects to primitive types
  • Using incompatible types in declaration
  • Missing 'new' keyword for object creation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes