Header Ad

Java program to use this keyword

In this tutorial, we are going to write a Java program to use this keyword in Java Programming with practical program code and step-by-step full complete explanation.

Java program to use this keyword


Java program to use this keyword.

 
class ThisTest
{
    int id;
    String name;
    
    ThisTest(int id,String name)
    {
        this.id = id;
            this.name = name;
    }

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


Output

 
142 Rahul
452 John


Post a Comment

0 Comments