posted 8 years ago
10 + 2 + "SUN" + 4 + 5
Evaluation starts from left side.
Steps:
10 + Now it looks at right side to check, is there any high precedence operator than +? answer is no so (All are additive operators so same precedence so left associative)
( 10 + 2 ) result = 12
12 + again it looks at right side to check, is there any high precedence operator than +? answer is no so
( 12 + "SUN" )
Explanation:
String conversion is performed because one operand is String i.e. "SUN" so 12 whose default primitive type is int is converted to Integer like new Integer(12); then this reference value is converted to type String by String conversion. Concatination of String using + operator uses StringBuilder's append method to append them and then converts to String using toString method of StringBuilder.
Now result = "12SUN"
( "12SUN" + 4 ) same like above String conversion process result = "12SUN4"
( "12SUN4" + 5 ) same like above String conversion process result = "12SUN45"
Final result = "12SUN45"
Edit: Then at last passes this String to parameterized constructor of StringBuilder i.e public StringBuilder(String str)