Knowee
Questions
Features
Study Tools

Which of the following declaration(s) is/are correct for a String?  Tick all correct answer(s).  No partial marks and no negative marks.Select one or more:String s2='null';String s1=null;String s4=(String)'\ufeed';String s3=(String)'abc';

Question

Which of the following declaration(s) is/are correct for a String?  Tick all correct answer(s).  No partial marks and no negative marks.Select one or more:String s2='null';String s1=null;String s4=(String)'\ufeed';String s3=(String)'abc';

🧐 Not the exact question you are looking for?Go ask a question

Solution

The correct declaration for a String in Java is:

String s1=null;

The other declarations are incorrect because:

  • String s2='null'; is incorrect because single quotes are used for char, not String. It should be "null".
  • String s4=(String)'\ufeed'; is incorrect because you can't cast a char to a String.
  • String s3=(String)'abc'; is incorrect because 'abc' is not a single character, and you can't cast it to a String.

This problem has been solved

Similar Questions

Which of the following declaration(s) is/are correct for a String?  Tick all correct answer(s).  No partial marks and no negative marks.

Which of the following statements about initializing strings is correct?Marks : 1Negative Marks : 0Answer hereStrings cannot be initialized at the time of declarationStrings can be initialized using double quotesStrings must always be initialized with a sizeStrings are automatically initialized to the null character

Which of the following statement(s) is (are) not correct so far as the initialization of a string is concerned?

Which of the following is the correct option for the following statement?    string* x, y;Select one:both x and y are pointer to string typesx is a pointer to a string, y is a stringNone of thesey is a pointer to a string, x is a string

Which of the following statements about initializing strings is correct?

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.