Explain the advantage of using ?this? keyword in Java. Implement the program that calculates the area of rectangle which make use of the constructor and the ?this? keyword.
May 4, 2010 at 1:31 PM
This keyword is used to represent an object constructed from a class in which it appears. It is also used to forward a call from one constructor in a class to another constructor in the same class. It helps to access class members and it provides access to the current instance. Within an instance method or a constructor, this is a reference to the current object.
As we know with in a program we declare the name of instance variables and local variables same. Now to avoid the confliction between them we use this keyword. The keyword helps us to avoid name conflicts