Back to Writing Classes

Lesson PreviewLesson 9 of 10 in this unit

5.9 this Keyword

Part of Writing Classes in AP® Computer Science A. Read the opening section, then create a free account for the full interactive lesson, practice, and progress tracking.

Before diving into the this keyword, let's quickly recap constructors. A constructor is a special method used to create and initialize an object when it's instantiated. It has the same name as the class and no return type.

At its core, the this keyword is a reference variable in Java. It represents the current object—the instance of the class in which the code is being executed. It is particularly useful when differentiating between class fields (variables declared in the class) and method parameters or local variables that share the same name.

Continue the full lesson in Stellar

Create a free account to unlock the remaining sections, checkpoints, course practice, and progress tracking for AP® Computer Science A.