Java Assignment Operators
In Java, there are three assignment operators.Assignment operator always follows Right To Left Associativity.
Simple Assignment
Chained Assignment
Compound Assignment
1.Simple Assignment:-
We can perform simple assignment at the time of declaration.
example:-
int a=10;
2.Chained Assignment :-
We can't perform simple assignment at the time of declaration.
example:-
int a,b,c,d;
a=b=c=d=20;
System.out.println(a+"....."+b+"....." +c+"....."+d)
output is
20.........20.........20.........20.........
BUT:
int a=b=c=d=20;
Compile Time Error: cannot find symbol
symbol: variable b
location: class name
3.Compound Assignment:-
When Assignment Operator is mixed with some other operator then the assignment is called as Compound Assignment.
example:-
int a=10;
a+=20;
System.out.println(a);
output is 20
Hint: a=a+20;
These are the following all possible combinations of Compound Assignment.
Note: In the Case of compound assignment operator internal type casting will be performed automatically.
No comments:
Post a Comment
Be the first to comment!
Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.
Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
Regards,
JavaByChetan
Back To Home