This Variable & Temporary Instances

The ‘this’ keyword is used to refer to the object of the class. It can be used inside any method of the same class to refer to the current object. When a class is created, its member functions are created only once in the memory space. Only one copy of the member function is created and shared by all the objects of the class. Data members are allocated memory space for each of the objects. Java explicitly uses the ‘this’ keyword to refer to the data members of an object. The ‘this’ keyword resolves the name-space collisions caused by hiding the local variable.

Explicit ‘this’ is used when the programmer uses the same name for the instance variable and local variable. Java explicitly uses ‘this’ keyword to refer to the data members of an object. The ‘this’ variable is an implicit argument to a method when it is called for an object. It is a reference to the object for which the method is being called and is used to access the member variables for the object. An explicit call to the constructor creates a temporary instance. A temporary instance exists only at run-time. It is anonymous, i.e., it does not bear any name. A temporary instance of a class means an anonymous object of the same class, which is short lived. Its benefit is when an object is repaired only for a very short time.

To Access the full content, Please Purchase