Deepesh my Question was why expression "a+b" and "c+a" is not giving error.
posted 11 years ago
lets see what happened on a+b
a is a String and b is an StringBuilder(i.e. OBJECT)
a+b=> a +b.toString();
(remembered we generally use OBJECT NAME to print with system.out.println which takes STRING argument like system.out.println("Object Created:"+obj) so always in concatenation with the String, result will be String.
it can be taken as
(a+b.toString()) , which will return an object of type STRING.
As you may be aware that you can pass String to object reference.
So Object d=newly created STRING.