Hi Anitha the arithmetic expression a+=b is a type of compound assignment operator and according to java language specification,I found that this expression is evaluated as :
"A compound assignment expression of the form E1 op= E2 is equivalent to E1 = (T) ((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once." Example :
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
short a=3;
double b=3.6;
System.out.println(a+=b); // expression is evaluated as a=(short)(a+b); type casting is happening here result is 6
System.out.println(a=a+b); // throws an error : incompatible types: possible lossy conversion from double to short
}
}
Reference : http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.26.2