Java OCA OCP Practice Question 127

Question

What is the output of the following?

public class Main {
   public static void main(String... args) {
      String chair, table = "TABLE";
      chair = chair + table;
      System.out.println(chair);
   }
}
A.   TABLE 
B.   TABLETABLE 
C.   nullTABLE 
D.   The code does not compile. 


D.

Note

The table variable is initialized to "TABLE".

chair is not initialized.

In Java, initialization is per variable and not for all the variables in a single declaration.

The second line tries to reference an uninitialized local variable and does not compile.

Option D is correct.




PreviousNext

Related