Java OCA OCP Practice Question 199

Question

What is the first line in the following code to not compile?

public static void main(String[] args) { 
        int Integer = 0;        // k1 
        Integer int = 0;        // k2 
        Integer ++;             // k3 
        int++;                  // k4 
} 
  • A. k1
  • B. k2
  • C. k3
  • D. k4


B.

Note

Integer is the name of a class in Java.

While it is bad practice to use the name of a class, this is legal.

k1 does compile.

It is not legal to use a reserved word as a variable name.

All of the primitives including int are reserved words.

k2 does not compile, and Option B is the answer.

Line k4 doesn't compile either, but the question asks about the first line to not compile.




PreviousNext

Related