Java OCA OCP Practice Question 2946

Question

Which of these lines compile? (Choose all that apply.)

1: public class Main { 
2: public void money() { 
3:    int _million = 1_000_000; 
4:    double aThousand = 1_000_.00; 
5:    double 100 = 100; 
6:    int hundred = 100.00; 
7:    float ten = 10d; 
8:    short one = 1; 
9: } } 
  • A. 3
  • B. 4
  • C. 5
  • D. 6
  • E. 7
  • F. 8


A,F.

Note

Option A is correct.

Identifiers are allowed to begin with underscores.

Numeric values are allowed to have underscores between two digits.

Option B is incorrect because underscores are not allowed adjacent to a decimal point.

Option C is incorrect because identifiers are not allowed to start with digits.

Option D is incorrect because decimal values are not allowed in int variables-they can only go in float or double types.

Option E is incorrect because 10d declares a double, and a double is bigger than a float.

Option F is correct because it is a straightforward variable assignment.




PreviousNext

Related