OCA Java SE 8 Building Blocks - OCA Mock Question Building Block 22








Question

Given the following class, which of the following lines of code can replace INSERT CODE HERE to make the code compile? (Choose all that apply)

     public class Main { 
           public static void main(String[] argv) { 
                     INSERT CODE HERE 
                  System.out.println(amount); 
           } 
     } 
  1. int amount = 9L;
  2. int amount = 0b101;
  3. int amount = 0xE;
  4. double amount = 0xE;
  5. double amount = 1_2_.0_0;
  6. int amount = 1_2_;
  7. None of the above.




Answer



B, C, D.

Note

0b is the prefix for a binary value.

0x is the prefix for a hexadecimal value.

This value can be assigned to many primitive types, including int and double.

A is wrong since 9L is a long literal value.

E is wrong because the underscore is immediately before the decimal. The underscore must be placed between two digits.

F is wrong since the underscore is the last character.