Concept Of This Keyword.

  This Keyword
         This is a reference variable that refers to the current object.

Usage Of Java this Keyword.
  1. this keyword can be used to refer current class instance variable.
  2. this() can be used to invoke current class constructor.
  3. this keyword can be used to invoke current class method (implicitly)
  4. this can be passed as an argument in the method call.
  5. this can be passed as argument in the constructor call.
  6. this keyword can also be used to return the current class instance.

/*Concept Of This keyword Example In Java.*/

//programming789.blogspot.com

class KeyTest

{

int id;

String name;

   KeyTest(int id,String name)
      {  
        this.id = id;
this.name = name;
       }
   void display()
       {
System.out.println(id+" "+name);
        }
   public static void main(String args[])
       {
KeyTest s1 = new KeyTest(142,"Bob");
KeyTest s2 = new KeyTest(452,"John");
s1.display();
s2.display();
        }
}

● Open notepad and add the code.
● Save the file as KeyTest.java.

Output:-
>java KeyTest
142 Bob
452 John