Single Choice Not Set

QWhich is a valid declarations of a String?

ID: #1992 Java Language Fundamental 16,434 views
Question Info
#1992Q ID
Not SetDifficulty
Java Language FundamentalTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A String s1 = null;
  • B String s2 = 'null';
  • C String s3 = (String) 'abc';
  • D String s4 = (String) '\ufeed';
Correct Answer

Explanation

Option A sets the String reference to null.

Option B is wrong because null cannot be in single quotes.

Option C is wrong because there are multiple characters between the single quotes ('abc').

Option D is wrong because you can't cast a char (primitive) to a String (object).

Share This Question

Challenge a friend or share with your study group.