Java OCA OCP Practice Question 760

Question

What is the output of the following?

public class Main { 
   public static void main(String[] black) { 
     String s = 'b'; 
     String tail = "B"; 
     s = s.concat(tail); 
     System.out.println(s); 
   } 
} 
  • A. b
  • B. bB
  • C. The code does not compile.
  • D. The code compiles but throws an exception at runtime.


C.

Note

The declaration of s is incorrect.

It tries to store a char into a String variable reference.

This does not compile, making Option C correct.

If this was fixed, the answer would be Option B.




PreviousNext

Related