The 'this' Reference Variable

In this lesson, you will learn about the 'this' reference variable.

The this Reference Variable

The this reference variable exists for every class. It refers to the current instance of a class. The this.memberName specifies that we are accessing the memberName of the current object.

Accessing a Field

We can use the this when we have a method argument which has the same name as a field. It’s always a good convention for the beginners to use the this keyword in their class implementation when initializing or accessing the fields. This will help us avoid any confusion or errors.

Let’s see it in action:

Get hands-on with 1200+ tech skills courses.