aspose file tools*
The moose likes Beginning Java and the fly likes The keyword 'this' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The keyword Watch "The keyword New topic
Author

The keyword 'this'

cheng jian
Greenhorn

Joined: Jul 28, 2008
Posts: 7
Hi.
Now i'm puzzled by the keyword 'this'.
Is anyone help me?
As detailed as possible!With some examples are best!
Thank you!
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Originally posted by cheng jian:
With some examples are best!


Try THis and let me know


Hope This Helps
Sagar Rohankar
Ranch Hand

Joined: Feb 19, 2008
Posts: 2902
    
    1

In java this is keyword , whcih points the current object which invokes instance methods !
Like , here is an example



'this.a' belongs to object which call the constructor , whereas right side 'a' is method local variable .

that`s used to resolve the ambiguity . If you remove keyword this, you cant assigned the values to instance variable ! Try this,



and SUN explains it beautifully !


[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39416
    
  28
You can also use this(); as the first line in an overloaded constructor to call another overloaded constructor of the same class. Obviously you can have arguments in the ().

If you are inside an inner class and want a reference to the object of the outer class associated with it, write

OuterClassName.this.foo();
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

Thanks Campbell
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39416
    
  28
You're welcome. And thanks to everybody else who replied.
cheng jian
Greenhorn

Joined: Jul 28, 2008
Posts: 7
Thanks!
I think i get something from the examples.
Here i learn many.
Thank you again!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The keyword 'this'