p.453
Chapter 6 answers
answer to question 9 reads:
"...Option D is also incorrect because a private instance variable is only accessible within the instance that created it...",
but further in answer to question 11 it is stated "...Options A, C, and D are true statements....", option C being "Two instances of
the same class may access each other’s private attributes".
Again, in question 15 there is piece of code, where a private attribute of new instance is accessed in static context. I modified it slightly:
package slopes;
public class Ski {
private int age = 18;
void slalom(Ski racer, int[] speed,
String name) {
racer.age = 19;
name = "Wendy";
speed = new int[1];
speed[0] = 11;
racer = null;
}
void setAge(int age){this.age = age;}
int getAge() {return age;}
public static void main(String... mountain) {
final Ski mySkier = new Ski();
mySkier.age = 16;
final Ski yourSkier = new Ski();
yourSkier.age = 17;
final int[] mySpeed = new int[1];
final String myName = "Rosie";
mySkier.slalom(yourSkier,mySpeed,myName);
System.out.println("yourSkier.age ="+ yourSkier.age);
}
}
and everything runs fine. By using setAge() and getAge() I checked that it is also OK if method slalom() of one instance is used from another class, sending to parameters another instance.
So it seems that answer to question 9 should be modified, may be along with question 9 itself.