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.

Satish Kanakala said:   3 years ago
The mentioned answer

String S = null is perfectly valid because it is the default value of the string. As conclusion, if we initialised any explicit value in double quotes like "null" or any "xxx". It will give results as mentioned in double-quotes.

Thank you


Post your comments here:

Your comments will be displayed after verification.