Java OCA OCP Practice Question 2375

Question

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

  • a bit a = 0;
  • b integer a2 = 7;
  • c long a3 = 0x10C;
  • d short a4 = 0512;
  • e double a5 = 10;
  • f byte a7 = -0;
  • g long a8 = 123456789;


c, d, f, g

Note

Options (a) and (b) are incorrect.

There are no primitive data types in Java with the names bit and integer.

The correct names are byte and int.

Option (c) is correct.

It assigns a hexadecimal literal value to the variable a3.

Option (d) is correct.

It assigns an octal literal value to the variable a4.

Option (e) is incorrect.

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

Option (f) is correct.

-0 is a valid literal value.

Option (g) is correct.

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




PreviousNext

Related