Java OCA OCP Practice Question 1443

Question

Which of the following statements are true?

Select 2 options

  • A. System.out.println (1 + 2 + "3"); would print 33.
  • B. System.out.println ("1" + 2 + 3); would print 15.
  • C. System.out.println (4 + 1.0f); would print 5.0
  • D. System.out.println (5/4); would print 1.25
  • E. System.out.println ('a' + 1 ); would print b.


Correct Options are  : A C

Note

All operands of type byte, char or short are promoted at least to an int before performing mathematical operations.

If one of the operands is larger than an int then the other one is promoted to the same type.

System.out.println ((float)5/4); will print 1.25.

If you remove the explicit cast (float), it will print 1.




PreviousNext

Related