7.9 The Object Reference this
When an object is instantiated, a copy of each of the instance variables is created. However, all objects of a class share one copy of the methods. How, then, does a method know for which object the method was called? In other words, how does a method know which object’s data it should get, set, or use to calculate a value? The answer is the special object reference named this.
When a method begins executing, the JVM sets the object reference, this, to refer to the object for which the method has been called. That object reference is called the implicit parameter. When a method references an instance variable, it will access the instance variable that belongs to the object that the implicit parameter references. ...
Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.