I know that \'this\' is acting as reference in Java. We can use it inside the class members only.
What I am asking is... because it is used in the members of the cl
Instance methods are invoked within the context of an actual instance, an actual object.
Within the instance method of a class
, this
(in most context) refers to this object. This is a relative reference: when the same method is invoked on another object, then this
within the execution of that method now refers to this second object.
For completeness, it should be mentioned that Java also has what is called "qualified" this
that can be used to refer to not the object that the method is invoked upon, but the enclosing object of an inner class
.
It can also appear, with some restriction, in constructors, to invoke another constructor of the same class. super
can also be used in this manner.
this
denotes a value that is a reference to the object for which the instance method was invoked, or to the object being constructed. this
.this
(possibly prefaced with explicit type arguments). They are used to invoke an alternate constructor of the same class.