Discussion Locked

java programming

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
what is the use of "this" in java programming language?

1 reply

by wjlarue

The 'this' keyword is typically used in object instance method or constructor to refer to the current object (can also 0be used in the initializer of an instance variable of a class). I like to think of it as a short cut that keeps from typing long object names.
In the following example, this refers to the newly created MyObject object, and assigns values to three properties:

function MyObject(property1, property2, property3)
{
this.property1= property1;
this.property2= property2; this.property3= property3;
}

The keyword 'me' in Visual Basic would be an equivalent.

Hope this explains it.

This discussion is closed to new replies.