+ 2
why?
String s=8+"hello" ? String s="8"+"hello"? what is the ans and why ?
3 Answers
+ 16
To be precise, it's a compilation error because s is already defined ;)
But you mean what is stored in s for both definitions... Answer is: 8hello for both. They're equal because everything after the = is casted to string internally if you use a string type.
+ 12
String s = 8 + "hello" casted in :
"8" + "hello" = 8hello
try this :
s= 1 + 2 + 3 + 'h' +"ell" + 'o' + 1 + 2 + 3;
can you explain why ?
+ 2
@NimWing Yuan
s=6hello123
Reason:
'+' operator has same priority and associativity will be left to right. So it will be like
1+2=3, 3+3=6, 6+'h'='6h','6h'+'ell'='6hell' and so on....