September 2011
Beginner
650 pages
15h 47m
English
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:

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 ...
Read now
Unlock full access