OCA Java SE 8 Mock Exam Review - OCA Mock Question 24








Question

Which of the following code to declare and initialize variables to store whole numbers are correct?

  1. bit a = 0;
  2. integer a2 = 7;
  3. long a3 = 0x11C;
  4. short a4 = 051;
  5. double a5 = 10;
  6. byte a7 = -0;
  7. long a8 = 123456789;




Answer



c, d, f, g

Note

A and B are incorrect. There are no primitive data types in Java named bit and integer. The correct names are byte and int.

C is correct. It assigns a hexadecimal literal value to the variable a3.

D is correct. It assigns an octal literal value to the variable a4.

E is incorrect. It defines a variable of type double, which is used to store decimal numbers, not integers.

F is correct. -0 is a valid literal value.

G is correct. 123456789 is a valid integer literal value that can be assigned to a variable of type long.