Here you need to understand two concepts: the evaluation rule from left to right Java and .
"A"+new C()
following the same rule. First it gets an “A,” which is a string literal, puts it somewhere. Then he evaluates
new C()
first, construct a C Object , then call the toString() method of C and get the value of C, which is " C ", then combines " A " and " C " together with println " AC ".
Inside the toString() method of the C object, there is System.out.print("B"); which is called when Java evaluates the above expression. It is printed before the evaluation is completed.
This is why " B " is printed first
Javascript is GOD
source share