class TestPrivate2 {
private int n;
}
public class TestPrivate {
private int n;
public void accessOtherPrivate(TestPrivate other) {
other.n = 10;// can use other class's private field,why??????????
System.out.println(other.n);
}
public void accessOtherPrivate(TestPrivate2 other) {
// other.n = 10;//can not access,i konw
// System.out.println(other.n);//
}
public static void main(String[] args) {
new TestPrivate().accessOtherPrivate(new TestPrivate());
}
}
look at TestPrivate's method:accessOtherPrivate.why it can use other class's private field why?