+ 2

Why do I get this output?

System.out.print(1+2+''Hello''+1+2); why do I get 3Hello12? *edit: apparently I've found out. that's because operations get solved sequentially from left to right so: 1+2=3 (int) 3+Hello= 3Hello (String) 3Hello+1 = 3Hello1 (String) 3Hello1+2= 3Hello12 (String)

1st Sep 2017, 7:35 AM
Michael Vigato
Michael Vigato - avatar
4 Answers
+ 10
hey michael , R U sure that this was answer , might a wrong quiz got approved actually + is overloading operator , for strings it conacatinate & for numbers it to addition // u will get 3Hello12 //AGAIN A WRONG QUIZ GOT APPROVED 😕
1st Sep 2017, 7:49 AM
Changed
Changed - avatar
+ 8
@empty , no bro answer will be 3Hello12
1st Sep 2017, 7:52 AM
Changed
Changed - avatar
+ 2
I cleaned it up
1st Sep 2017, 8:06 AM
Michael Vigato
Michael Vigato - avatar
0
why won't the answer be 3hello3
3rd Sep 2017, 1:23 AM
Abubakar Sadiq
Abubakar Sadiq - avatar