在comf方法中,this.num==d.num;为什么d能访问自己的num值呢?不是私有了吗?
class Demo {
private int num;
Demo(int num){
this.num=num;
}
public boolean com(Demo d){
return this.num==d.num;
}
}
class Test {
public static void main(String[] args){
Demo d1 = new Demo(22);
Demo d2 = new Demo(33);
System.out.println(d1.com(d2));
}
}
private表示一个类的私有属性,只能在本类中访问到,在其他的类中无法进行访问。private的访问控制是针对类来检查的,而非对象。