Java Programming - Language Fundamentals - Discussion

Discussion Forum : Language Fundamentals - General Questions (Q.No. 13)
13.
Which is a valid declarations of a String?
String s1 = null;
String s2 = 'null';
String s3 = (String) 'abc';
String s4 = (String) '\ufeed';
Answer: Option
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).

Discussion:
11 comments Page 2 of 2.

Purnima said:   1 decade ago
Then String s="null"; is it write?


Post your comments here:

Your comments will be displayed after verification.