Java OCA OCP Practice Question 437

Question

Which of the following statements will compile without any error?

Select 4 options

  • A. System.out.println ("a"+'b '+63);
  • B. System.out.println ("a"+63);
  • C. System.out.println ('b '+new Integer (63));
  • D. String s = 'b '+63+"a";
  • E. String s = 63 + new Integer (10);


Correct Options are  : A B C D

Note

+ is overloaded such that if any one of its two operands is a String then it will convert the other operand to a String and create a new string by concatenating the two.

In 63+"a" and "a"+63, 63 is converted to "63" and 'b' +"a" and "a"+'b', 'b' is converted to "b".

In 'b'+ 63 , 'b' is promoted to an int i.e. 98 giving 161.




PreviousNext

Related