Which three are valid declarations of a char? - ProProfs Discuss
Topics
Products
Follow Us:

Which three are valid declarations of a char?



A. Char c1 = 064770;
B. Char c2 = face ;
C. Char c3 = 0xbeef;
D. Char c4 = \u0022;
E. Char c5 = \iface ;
F. Char c6 = \uface ;

This question is part of

JAVA FUNDAMENTALS TEST
Asked by Ackerley, Last updated: Feb 16, 2020

+ Answer
Request

1 Answer

John Smith

John Smith

Answered Sep 09, 2016

Char c1 = 064770;-2. char c3 = 0xbeef;-3. char c6 = \ \\uface\ ;-(1), (3), and (6) are correct. char c1 = 064770; is an octal representation of the integer value 27128, which is legal because it fits into an unsigned 16-bit integer. char c3 = 0xbeef; is a hexadecimal representation of the integer value 48879, which fits into an unsigned 16-bit integer. char c6 = \\uface; is a unicode representation of a character.char c2 = face; is wrong because you cant put more than one character in a char literal. the only other acceptable char literal that can go between single quotes is a unicode value, and unicode literals must always start with a \\u.char c4 = \\u0022; is wrong because the single quotes are missing.char c5 = \\iface; is wrong because it appears to be a unicode representation (notice the backslash), but starts with \\i rather than \\u.
 

Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer

Email Sent
We have sent an email to your address "" with instructions to reset your password.