Assignment Operator

Assignments

The following is the list of all possible compound assignment operator.

+ =            & =                  % =

– =             | =                 >>> =

* =            ^ =                << =

/ =            >> =

In the case of compound assignment operator, the required type casting is performed automatically by the compiler.

byte b = 20 ;

b + = 20 ;

System.out.println ( b ) ; // 30

b = (byte) (b+20) // internal process

Chained Assignment operator

int a, b, c, d ;

a = b = c = d = 30 ;

System.out.println ( a + “—” + b + “—-” + c + ” —–” + d ) ; // 30—30—-30 —–30

*** We can’t use chained assignment at the time of declaration.

int a= b= c=d ; // compile time error

int a, b, c, d ;

a= b= c= d= 100 ;

a+= b+= c/= d%= 20 ;

System.out.println( a+ “—-” + b+ “—–” + c+ “—–” + d ) ; //  63—33—-3 —–10

Leave a Reply