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








Question

Which of the options are correct for the following code?

public class Main {                                // line 1 
    public static void main(String[] args) {       // line 2 
        char a = 'a';                              // line 3 
        char b = -10;                              // line 4 
        char c = '1';                              // line 5 
        integer d = 1;                             // line 6 
        System.out.println(++a + b++ * ++c-- - d); // line 7 
    }                                              // line 8 
}                                                 // line 9 
  1. Code at line 4 fails to compile.
  2. Code at line 5 fails to compile.
  3. Code at line 6 fails to compile.
  4. Code at line 7 fails to compile.




Answer



a, c, d

Note

A is correct. The code at line 4 fails to compile because you can't assign a negative value to a char data type without casting.

C is correct. There is no primitive data type with the name "integer." The valid data types are int and Integer.

D is correct. The variable d remains undefined on line 7 because its declaration fails to compile on line 6.