this KEYWORD

can you please tell me..what does ":this" KEYWORD do... apart from refering to instance varible in a class...
[130 byte] By [solemnsatyaa] at [2007-11-26 12:44:16]
# 1
search google for "java +this keyword" ;-)
Norweeda at 2007-7-7 16:21:42 > top of Java-index,Java Essentials,New To Java...
# 2

Using this with a Constructor

"From within a constructor, you can also use the this keyword to call another constructor in the same class".

"Doing so is called an explicit constructor invocation. "

Here's another Rectangle class, with a different implementation from the one in the Objects section.

public class Rectangle

{

private int x, y;

private int width, height;

public Rectangle() {

this(0, 0, 0, 0);

}

public Rectangle(int width, int height) {

this(0, 0, width, height);

}

public Rectangle(int x, int y, int width, int height) {

this.x = x;

this.y = y;

this.width = width;

this.height = height;

}

...

}

This class contains a set of constructors. Each constructor initializes some or all of the rectangle's member variables. The constructors provide a default value for any member variable whose initial value is not provided by an argument. For example, the no-argument constructor calls the four-argument constructor with four 0 values and the two-argument constructor calls the four-argument constructor with two 0 values. As before, the compiler determines which constructor to call, based on the number and the type of arguments.

If present, the invocation of another constructor must be the first line in the constructor.

COULD NOT UNDERSTAND PLS HELP

solemnsatyaa at 2007-7-7 16:21:42 > top of Java-index,Java Essentials,New To Java...
# 3
this means "The current instance of the Object I'm in" sort of.When you use this you're calling stuff on the current instance. Which is why you can't use this in a static context, b/c there's no associated instance.
Norweeda at 2007-7-7 16:21:42 > top of Java-index,Java Essentials,New To Java...
# 4

> "From within a constructor, you can also use the this

> keyword to call another constructor in the same

> class".

>

> "Doing so is called an explicit constructor

> invocation. "

<snip/>

> For example, the no-argument constructor calls the

> four-argument constructor with four 0 values

> COULD NOT UNDERSTAND PLS HELP

Oh come on... can't you at least provide some insight into what exactly you "could not understand" about this?

Lokoa at 2007-7-7 16:21:42 > top of Java-index,Java Essentials,New To Java...