jaga D sh jaga D sh - 1 year ago 133
Java Question

Core java printing statement

Why does java compiler gives


as output when I ever tried to print


. Please explain in detail . thank you)

Answer Source

'2' is a char, so '2' + '2' adds the int value of that character to itself (50+50) and then appends "a" to it, giving you 100a.

"a" + '2' + '2' performs String concatenation, since the first operand is a String. Therefore you get a22.

Note that the expressions are evaluated from left to right, so the types of the first two operands determine whether + will perform an int addition or a String concatenation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download