Why does concatenated characters print a number?
In the second case it adds the unicode codes of the two characters (G - 71 and o - 111) and prints the sum. This is because char
is considered as a numeric type, so the +
operator is the usual summation in this case.
+
operator with character constant 'G' + 'o'
prints addition of charCode and string concatenation operator with "G" + "o"
will prints Go
.
The plus in Java adds two numbers, unless one of the summands is a String, in which case it does string concatenation.
In your second case, you don't have Strings (you have char
, and their Unicode code points will be added).