[size=medium]网上看到这个文章,表示没理解.http://my.oschina.net/magicly007/blog/164191
看代码吧:[/size]
看代码吧:[/size]
class TestPrivate2 {
private int n;
}
public class TestPrivate {
private int n;
public void accessOtherPrivate(TestPrivate other) {
other.n = 10;//这里是可以访问同类型的其他对象other的private字段的
System.out.println(other.n);
}
public void accessOtherPrivate(TestPrivate2 other) {
// other.n = 10;//编译错误
// System.out.println(other.n);//编译错误
}
public static void main(String[] args) {
new TestPrivate().accessOtherPrivate(new TestPrivate());
}
}