O'Reilly logo

Java, A Beginner’s Guide, 5th Edition by Herbert Schildt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The this Keyword

Before concluding this chapter it is necessary to introduce this. When a method is called, it is automatically passed an implicit argument that is a reference to the invoking object (that is, the object on which the method is called). This reference is called this. To understand this, first consider a program that creates a class called Pwr that computes the result of a number raised to some integer power:

Image

As you know, within a method, the other members of a class can be accessed directly, without any object or class qualification. Thus, inside get_pwr( ), the statement

means that the copy of val associated with the invoking ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required