Reference Of a class
- we can initialized the variable of class by using an existing instance of the class and now that variable is known as Reference. References of the class will not have any memory allocation. They will be consuming the memory of the instance that is assigned to it for Initialization.
First f1 = new First (); // Instance
First f2 = f1 ; // f2 is reference
In the above case because the Instance and Reference are accessing the same object memory, any modifications that are performed on the member through the Instance reflects object, and we will be access them through the reference and vice versa.
Note : - When an Instance and reference are accessing the same memory, and if null is assigned to any one of them still the other can access the memory as it is.
No comments:
Post a Comment