Share this post on:

Let us Discuss that How can we use This Keyword in Java. There are Following ways by which we can use This keyword in Java.

  1. This keyword in Java is used to refer current class instance variable.
  2. This keyword in Java can be used to invoke current class method.
  3. This keyword can be used to invoke current class constructors.
  4. This keyword can be used to pass as an arguments in the method call.
  5. This keyword can be used to return the current class instance from the method.
  6. This keyword can be used to pass an arguments in the constructors call

Example :

public class ThisDemo {
int i;
void setvalue(int i)
{
    this.i=i;
}
void show()
{
    System.out.println(i);
}

public static void main(String[] args)
{
    ThisDemo x1=new ThisDemo();
    x1.setvalue(100);
    x1.show();
}}

Share this post on:
Avatar Raiyan

Author: Raiyan

Hi, I guess you're here because you want to know a bit about me. huh? I am not so good on talking about myself but I'll give a short about me.

My Name is Raiyan. I am a Professional Application Developer and a Blogger.
I started this website to Share my Knowledge. Here I provide all my knowledge whatever I earned till now.

One Comment

  1. Pingback: What are Important topics in java Interview? - ArzaTechs

Leave a Comment

Your email address will not be published. Required fields are marked *