Translate

Saturday 20 December 2014

this keyword in java

'this' is a reference variable that refers to the object that has called the member function. 'this' is available in all methods of a class except static methods. It is created implicitly so we don't need to declare it.

class Money
{
     private int rs, paisa;
     public void set (int rs, int paisa)
    {
       this.rs = rs;
       this.paisa = paisa;
    }
}

Now in above example rs and paisa to the left of equal op belongs to class and to the right are arguments passed.

No comments:

Post a Comment

Total Pageviews