Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2010
    Posts
    4
    Rep Power
    0

    Default Java Beginner: 'this' keyword?

    Hi ... can u please explain me the functionality of 'this' keyword (with an example). Its concept is nt clear to me. :confused:
    Last edited by atul_kumar2038; 08-31-2010 at 06:25 PM.

  2. #2
    imorio is offline Senior Member
    Join Date
    Aug 2010
    Posts
    127
    Rep Power
    0

    Default

    The "this" keyword is the refrence of the class the methode it's used in is in.

  3. #3
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

  4. #4
    siva_vs_siva is offline Member
    Join Date
    Aug 2010
    Posts
    31
    Rep Power
    0

    Default

    this keyword used to specify the current object...
    here is one example..


    public class ex1 {
    int a=0;
    public static void main(String arg[])
    {
    ex1 ob1=new ex1(10); //passing value
    ex1 ob2=new ex1(20);
    ob1.display();
    ob2.display();
    }
    ex1(int b)
    {
    a=b;

    }
    void display()
    {
    System.out.println("Current A value "+this.a); //current object values

    }

    }

  5. #5
    rohitjava is offline Member
    Join Date
    Aug 2010
    Posts
    13
    Rep Power
    0

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •