Showing posts with label How to Use This Key Word in Java. Show all posts
Showing posts with label How to Use This Key Word in Java. Show all posts

Monday, 15 September 2014

This Key Word in Java

Structure of the Problem Requirements 

In this problem we will learn how to use this in Java programs .The (this) keyword can be used inside the class or methods to referrer the object whose methods or constructor is being called. In variables handling (this ) keyword is very useful. Here is the source code of this problem which help you in better inderstanding.

SOURCE CODE




class ThisDemo
{
public static void main(String args[])
{
example e=new example();
e.Mul(30,20);
e.display();
}
}
//Sub Class
public class example
{
int x,y,z;
void Mul(int x,int y)
{
this.x=x;
this.y=y;
z=x*y;
}
void display()
{
System.out.println("Multiplication is :"+z);
}
}

                      Output of the Program


The use of this keyword
The use of this keyword in Java