0 votes
in JAVA by
Which of the following is a valid declaration of a char?

i) char ch = '\utea';

ii) char ca = 'tea';

iii) char cr = \u0223;

iv) char cc = '\itea';

1 Answer

0 votes
by

i) char ch = '\utea';

Reason: 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 other options are not valid because:

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

Related questions

0 votes
asked Apr 10, 2021 in JAVA by Robindeniel
0 votes
asked Apr 8, 2021 in JAVA by SakshiSharma
...