1. The new operator instantiates a class by allocating memory for a new object and returning a reference to that memory.
The new operator instantiates means when we create an object of class it allocate space on memory to store
the data of respective objects return an address or reference of memory location where data resides.
Example:
public class Math {
int x = 5;
public int Add(int no1, int no2) {
return no1 + no2;
}
}
public static void main(String[] args) {
Math myObj = new Math();
System.out.println(myObj.x);
}
Math myObj = new Math() statement is initialization and myObj is an object of Math class.
2. The new operator returns a reference to the object is created.
In above example 'new Math();' is initialization which will return the reference or address of memory.
We will get all data members (x) and methods (Add).