ATTN AP Computer Science Lovers... An easy question about the "this" command!

chilldude
Wed, 01 May 2013 00:13:22 +0000

The only times you need to use this are the following:

1. when overloading a constructor

2. when you have a field and an instance variable with the same name
example:
public class Foo {

private int bar;

public Foo() {
this(0);
}

public Foo(int bar) {
this.bar = bar;
}

}