in Technology by

Which of the following is a valid declaration of a char?

a) char ch = '\utea';

b) char ca = 'tea';

c) char cr = \u0223;

d) char cc = '\itea';

🔗Reference: stackoverflow.com

🔗Source: Java Interview Questions and Answers

1 Answer

0 votes
by

Answer: (a) char ch = '\utea';

Explanation: A char literal may contain a Unicode character (UTF-16). We can directly use these characters only if our file system allows us, else use a Unicode escape (\u) such as "\u02tee". The char literals are always declared in single quotes (').

The option b, c, and d, are not valid because:

  • In the option b), to make a String valid char literal, we should add prefix "\u" in the string.
  • In the option c), single quotes are not present.
  • In the option d), "\i" is used in place of "\u."

Hence, the correct answer is the option (a).

Related questions

0 votes
    Which is a valid declaration within an interface? A)protected short stop = 23; b)final void madness(short stop); ... (double duty);? Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    Which of the following for loop declaration is not valid? a) for ( int i = 99; i >= 0; ... ;Reference: stackoverflow.com 🔗Source: Java Interview Questions and Answers...
asked Dec 19, 2020 in Technology by Editorial Staff
0 votes
    Which of the following is a valid declaration of an object of class Box? (a) Box obj = new Box( ... programming questions and answers pdf, java interview questions for beginners...
asked Oct 26, 2021 in Education by JackTerrance
0 votes
    Which of the following is used to terminate the function declaration in C++? a) ; b) ] c) ) d) :...
asked Oct 19, 2022 in Education by JackTerrance
0 votes
    which of the following java declaration of the string Array is correct? Select the correct answer from above options...
asked Dec 29, 2021 in Education by JackTerrance
0 votes
    Rewrite the following JAVA program segment using switch case.. char code; if(code=='B'||code=='b') System.out. ... now .plz help me . Select the correct answer from above options...
asked Dec 17, 2021 in Education by JackTerrance
0 votes
    Which of these is an incorrect array declaration? (a) int arr[] = new int[5] (b) int [] arr ... java programming questions and answers pdf, java interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    What is true about functions : I) Functions are objects II) Can be assigned to a variable III) Can be anonymous IV) Return value type has ... , III 3. I, II, III, IV 4. I, II, IV...
asked Feb 25, 2021 in Technology by JackTerrance
+1 vote
    What is the difference between variable declaration and variable definition in C-Programming?...
asked Nov 9, 2020 in Technology by JackTerrance
0 votes
    What is true about functions : I) Functions are objects II) Can be assigned to a variable III) Can be anonymous IV) Return value type has ... , III C) I, II, III, IV D) I, II, IV...
asked Oct 9, 2020 in Technology by JackTerrance
0 votes
    Which of these is a wrapper for simple data type char? (a) Float (b) Character (c) String (d) ... java programming questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    Which of these methods of Character wrapper can be used to obtain the char value contained in Character object ... questions and answers pdf, java interview questions for beginners...
asked Oct 25, 2021 in Education by JackTerrance
0 votes
    How to convert a date to char in Oracle? Give one example....
asked Dec 18, 2020 in Technology by JackTerrance
0 votes
    How many Articles are there in the United Nations Declaration of Human Rights? (a) 30 (b) 20 (c) 40 (d) 50 Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
0 votes
    When was the Declaration of the Rights of Child proclaimed? (a) 30th November 1959 (b) 20th November 1959 (c) ... 1959 (d) 30th December 1959 Please answer the above question....
asked Aug 4, 2022 in Education by JackTerrance
...