a
is of type char
and chars can be implicitly converted to int
. a
is represented by 97 as this is the codepoint of small latin letter a
.
System.out.println('a'); // this will print out "a"
// If we cast it explicitly:
System.out.println((int)'a'); // this will print out "97"
// Here the cast is implicit:
System.out.println('a' + 0); // this will print out "97"
The first call calls println(char)
, and the other calls are to println(int)
.
Related: In what encoding is a Java char stored in?
2
solved Do chars have intrinsic int values in Java?