this keyword in java meaning code example
Example 1: this keyword in java
class Demo
{
int m;
int n;
public void setValue(int m, int n)
{
this.m = m;
this.n = n;
}
public void showValue()
{
System.out.println("Value m = " + m);
System.out.println("Value n = " + n);
}
}
public class ThisExample
{
public static void main(String[] args)
{
Demo obj = new Demo();
obj.setValue(5,6);
obj.showValue();
}
}
Example 2: this keyword in java
import java.util.*;
class Demo
{
int m;
int n;
public void setValue(int m, int n)
{
m = m;
n = n;
}
public void showValue()
{
System.out.println("Value m = " + m);
System.out.println("Value n = " + n);
}
}
public class ThisKeywordDemo
{
public static void main(String[] args)
{
Demo obj = new Demo();
obj.setValue(5, 6);
obj.showValue();
}
}