This Key Word in Java

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.


  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


Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment