![]() |
![]() |
![]() |
![]() |
![]() |
|
As you learned in Segment 295, this can be viewed as a
special instance-method parameter whose value is the instance method's
target. If you wish, you can use this as an explicit target. Thus,
you can redefine the Movie class's describe method as
follows:
public class Movie extends Attraction {
// Rest of Movie definition
// Define rating:
public int rating () {
return script + acting + direction;
}
// Define describe
public void describe () {
System.out.println(
"Movie with rating "
+ this.rating() + " lasts "
+ this.getMinutes() + " minutes"
);
}
}
Thus, the real result of leaving out an explicit target is that Java
takes the target to be the value of the this parameter.