File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes about Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "about "this "" Watch "about "this "" New topic

about "this "

lang lang

Joined: Nov 01, 2003
Posts: 8
I'm a Java beginer.Now I'm confused about "this ",would you please tell me
about "this "in different aspects? If you add some examples ,I will be greatful.
thanks a millon!
William Barnes
Ranch Hand

Joined: Mar 16, 2001
Posts: 986

"this" is a referance to the current object.

Please ignore post, I have no idea what I am talking about.
Ransika deSilva
Ranch Hand

Joined: Feb 18, 2003
Posts: 524
I think this might too explain what this means
Say if you have a class like this
public class Test {
int x = 0;
public Test(int x) {
x = x;

So how to deferenciate the two x's which one is global and one is local?
you can say
this.x = x;
now the 'this.x' is the global variable and x, which is assigned to it is the local variable.
Hope it is clear.

SCJP 1.4, SCMAD 1.0<br />SCWCD, SCBCD (in progress)
I agree. Here's the link:
subject: about "this "
It's not a secret anymore!