Explain This

This: It is a Java reserved word with numerous different uses:

A) Within a constructor, it might be employed as the first statement to call the other constructor in similar class. For illustration:

              // Initialize with default values.
              public Heater()
              {
                  // Use another constructor.
                  this(15, 20);
              }

              // Initialize with the given values.
              public Heater(int min,int max)
              {
                  ...
              }
             
B) Within a method or constructor, it might be employed to distinguish between a field and a parameter or method variable of similar name. For example:

              public Heater(int min,int max)
              {
                  this.min = min;
                  this.max = max;
                  ...
              }
             
C) It can be employed as a reference to the present object, usually in order to pass the reference to the other object:
               talker.talkToMe(this);

   Related Questions in Programming Languages

©TutorsGlobe All rights reserved 2022-2023.