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

The Author

Narayanaswamy

Hello! I am Narayanaswamy founder and admin of narayanatutorial.com. I have been working in IT industry more than 7 years. NarayanaTutorial is my web technologies blog. My specialties are Java / J2EE, Spring, Hibernate, Struts, Webservices, PHP, Oracle, MySQL, SQLServer, Web Hosting and Website Development. I am a self learner and passionate about training and writing. I am always trying my best to share my knowledge through my blog.

Leave a Reply