Assignment in Java Programming

Assignment in Java Programming

Previous Home Next

 

Assignment operator is mainly used to assign value to the variables.
This operator can also be used on objects to assign object references

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.
Assignment operator is '='
 Assignment operator

int i=4;
int j=8;   //assignment operator = is used to assign the value to the variables i,and j ,the values assigning are 4and 8 respectively.


 
public class AssignmentOperators
{

public AssignmentOperators()
{
// Assigning Primitive Values
int i, j, k;
i = 10; // j gets the value 10.
j = 5; // j gets the value 5. Previous value is overwritten.
k = i+j; // k gets the value 15.
System.out.println("The value of i is : " + i);
System.out.println("The value of j is : " + j);
System.out.println(" The value of k is:"+ k);
Public static void main( String arg[] )
{
new Assignmentoperator()

}
}


Previous Home Next