IndiaBIX
IndiaBIX
Start typing & press "Enter" or "ESC" to close
  • Home
  • Jobs
  • Results
  • Current Affairs
  • GK
  • Online Test
  • HR Interview
  • BLOG

Which three are valid declarations of a char? 1 char c1 = 064770; 2 char c2 = 'face'; 3 char c3 = 0xbeef; 4 char c4 = \u0022; 5 char c5 = '\iface'; 6 char c6 = '\uface';

  • Home
  • Computer Science & Engineering
  • Java Programming Questions and Answers
  • Language Fundamentals - General Questions
  • Discuss - 1316
1. 

Which three are valid declarations of a char?

1 char c1 = 064770;

2 char c2 = 'face';

3 char c3 = 0xbeef;

4 char c4 = \u0022;

5 char c5 = '\iface';

6 char c6 = '\uface';

[A]. 1, 2, 4
[B]. 1, 3, 6
[C]. 3, 5
[D]. 5 only

Answer: Option B

Explanation:

(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 can't 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'.

Workspace Report
Leave a Comment

Computer Science & Engineering :: Java Programming Questions and Answers : More Exercises

  • Language Fundamentals - General Questions
  • Operators and Assignments - Finding the output
  • Exceptions - Finding the output
  • Inner Classes - General Questions
  • Height and Distance - Garbage Collections
  • Java.lang Class - General Questions
  • Declarations and Access Control - General Questions
  • Flow Control - General Questions
  • Objects and Collections - General Questions
  • Threads - General Questions
  • Assertions - Finding the output

Questions & Answers

Aptitude Chemical Engineering Civil Engineering Computer Science & Engineering Current Affairs Data Interpretation Electrical & Electronics Engineering Electronics & Communication Engineering General Knowledge Logical Reasoning Mechanical Engineering Non Verbal Reasoning Verbal Ability Verbal Reasoning

Interviews

HR Interview

Jobs

Sarkari Jobs

Results

Rojgar ResultSarkari Result

Admission

Admission 2023

Admit Card

Admit Card 2023

Answer Key

Answer Key 2023
copyright
Privacy Policy
© 2026 IndiaBIX. All Rights Reserved.

Report