Java OCA OCP Practice Question 2954

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 void admission() { 
             // INSERT CODE HERE 
             System.out.println(amount); 
      } 
} 
  • A. int amount = 9L;
  • B. int amount = 0b101;
  • C. int amount = 0xE;
  • D. double amount = 0xE;
  • E. double amount = 1_2_.0_0;
  • F. int amount = 1_2_;
  • G. None of the above


B,C,D.

Note

0b is the prefix for a binary value, making option B correct.

0X is the prefix for a hexadecimal value.

This value can be assigned to many primitive types, including int and double, making options C and D correct.

Option A is incorrect because 9L is a long value.

long amount = 9L would be allowed.

Option E is incorrect because the underscore is immediately before the decimal.

Option F is incorrect because the underscore is the very last character.




PreviousNext

Related