In this tutorial, you will see the use of assignment operater in java.
Java assignment operator example.
In this example, you will see the use of java assignment operator. The symbol of
assignment operator is "=". It is used for assigning the value to a variable. If
the value already exists in that variable then it will be overwritten.
you can also assign reference of other object.
The AssignmentOperator is a class in our program. It has a
integer variable name "num". The obOperater is a object of
AssignmentOperater class. It is used for accessing variable,
and reassigning that variable.
AssignmentOperater.java
package com.devmanuals; public class AssignmentOperater { public static int num = 18; public static void main(String[] args) { AssignmentOperater obOperater = new AssignmentOperater(); System.out.println("Value of variable."); System.out.println("Before assign value :"+obOperater.num); System.out.println("New value of variable after using assignment : "); obOperater.num=20; System.out.println("New Value : "+obOperater.num); } }Output:
Value of variable assign by assignment operator.
18 |
[ 0 ] Comments