‘ this ‘ KEYWORD


The this keyword is useful when you are trying to access the object that you are invoked in a  method . Confused! let’s see .

  1. Sometimes a method will need to refer the object that invoked it . Here , If you want to invoke a method into existence , then you are using object to invoke that particular method.So  if you want to refer the data within the object , then you will use  this keyword .
  2. this can be used inside any method to refer to the current object .
  3. That is , this is always reference to the object on which the method was invoked .
  4. You can use this anywhere a reference to an object of the current class type is permitted.

For better understanding actually what this is , consider the following example .

PROGRAM ON   ‘this’  KEYWORD :

This.java

IN THE ABOVE PROGRAM THE DEFAULT VALUES OF X , Y, AND Z ARE ZERO

MEMORY ALLOCATION :

This.java

PROGRAM 2 :

This2.java

IN THE ABOVE PROGRAM THE DEFAULT VALUE OF X IS 200. If You want the actual value of x then make this statement

System.out.println(” The original value of x is : “+t.x); // it prints the value of actual ‘x’ . That is, the instance variable value.

IMPORTANT POINTS :

  1. Here , you should remember one thing that , every method will contain ‘this‘ block with respect to the object . That is , when you are invoking a method with respect to some ‘t‘ object , then the method inside the ‘this’ will refer to that particular ‘t‘ object .
  2. Whenever , an object is created , then the object will automatically filled with the instance variables with their respected values ( default values). This you will be clearly  understands by  the time of constructors . 
If you want some more examples plz ping by block with  what type of example  you want . Thank you 🙂

14 responses

  1. you have done a marvellous job by providing this post. it will help a lot the people who are searching for information. thanks for sharing. lista de email lista de email lista de email lista de email lista de email

    1. Thank you for your valuable time. And we have shifted this website to http://www.javafrombasics.com , with great design and much more information. We Java experts are providing the free Java course which is absolutely for beginners.

  2. excellent information. i have learned quite a few very helpful information from your blog. thank you very much. lista de email lista de email lista de email lista de email lista de email

  3. I simply want to tell you that I am newbie to blogs and definitely savored this website. Most likely I’m likely to bookmark your blog . You definitely have tremendous writings. Bless you for revealing your blog.

    1. Thank you for your valuable time. And we have shifted this website to http://www.javafrombasics.com , with great design and much more information. We Java experts are providing the free Java course which is absolutely for beginners.

  4. I just want to tell you that I am very new to blogging and site-building and actually liked your web page. More than likely I’m planning to bookmark your blog post . You surely come with very good writings. Thanks a lot for sharing with us your webpage.

    1. Thank you for your valuable time. And we have shifted this website to http://www.javafrombasics.com , with great design and much more information. We Java experts are providing the free Java course which is absolutely for beginners.

    1. Thank you for your valuable time. And we have shifted this website to http://www.javafrombasics.com , with great design and much more information. We Java experts are providing the free Java course which is absolutely for beginners.

  5. Great work! This is the kind of information that are supposed to be shared
    around the web. Disgrace on Google for no longer positioning this post upper!

    Come on over and discuss with my site . Thanks =)

    1. Thank you for your valuable time. And we have shifted this website to http://www.javafrombasics.com , with great design and much more information. We Java experts are providing the free Java course which is absolutely for beginners.

  6. Woah! I’m really digging the template/theme of this site.
    It’s simple, yet effective. A lot of times it’s very difficult
    to get that “perfect balance” between usability and visual appeal.

    I must say that you’ve done a superb job with this.
    Also, the blog loads super quick for me on Chrome. Outstanding Blog!

    1. Thank you for your valuable time. And we have shifted this website to http://www.javafrombasics.com , with great design and much more information. We Java experts are providing the free Java course which is absolutely for beginners.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: