//Program with out this keyword
class Test
{
int a,b;
void setData(int a,int b)
{
a=a;
b=b;
}
void showData()
{
System.out.print("value of a=" +a);
System.out.println();
System.out.print("value of b=" +b);
}
public static void main(String[] args)
{
Test obj=new Test();
obj.setData(10,20);
obj.showData();
}
}
output:
//Program with this keyword
class Test
{
int a,b;
void setData(int a,int b)
{
this.a=a;
this.b=b;
}
void showData()
{
System.out.print("value of a=" +a);
System.out.println();
System.out.print("value of b=" +b);
}
public static void main(String[] args)
{
Test obj=new Test();
obj.setData(10,20);
obj.showData();
}
}
output:
class Test
{
int a,b;
void setData(int a,int b)
{
a=a;
b=b;
}
void showData()
{
System.out.print("value of a=" +a);
System.out.println();
System.out.print("value of b=" +b);
}
public static void main(String[] args)
{
Test obj=new Test();
obj.setData(10,20);
obj.showData();
}
}
output:
//Program with this keyword
class Test
{
int a,b;
void setData(int a,int b)
{
this.a=a;
this.b=b;
}
void showData()
{
System.out.print("value of a=" +a);
System.out.println();
System.out.print("value of b=" +b);
}
public static void main(String[] args)
{
Test obj=new Test();
obj.setData(10,20);
obj.showData();
}
}
output:
No comments:
Post a Comment