Assignment operator is the most common operator almost used with all programming languages. It is represented by "=" symbol in Java which is used to assign a value to a variable lying to the left side of the assignment operator. But, If the value already exists in that variable then it will be overwritten by the assignment operator (=). This operator can also be used to assign the references to the objects. Syntax of using the assignment operator is: <variable> = <expression>;
For example:
int counter = 1;
String name = "John";
boolean rs = true;
Shape s1 = new Shape(); // creates new object
Shape s2 = s1; //assigning the reference of s1 to s2
Comments
Leave a comment