Core java printing statement -
why java compiler gives
100a
as output when ever tried print system.out.println('2'+'2'+"a")
,
a22
for system.out.println("a"+'2'+'2')
. please explain in detail . thank you)
'2' char, '2' + '2' adds int value of character (50+50) , appends "a" it, giving 100a.
"a" + '2' + '2' performs string concatenation, since first operand string. therefore a22.
note expressions evaluated left right, types of first 2 operands determine whether + perform int addition or string concatenation.
Comments
Post a Comment