在JAVA中,只有public 友好的(default),修饰类。
1、同一包中,都可以访问;
2、不同包中,只有 public可以访问;
而public protected default private 修饰方法和变量。
1、public 同一包和不同包的类,都可以访问。private 只有类自己可以访问;
2、友好类和protected
a、在同一包中,不管子类还是其他类,都可以访问;
b、在不同包中,不管子类还是其他类,都不可以访问;
3、友好类和protected 区别,是在不同包中的继承方面;
a、不同包中,只有 protected 被子类使用,友好类是不可以被子类使用的;
b、假设 (Father Child Brother) Child和Brother 在同一个包中,
Father 自己在一个包中,Child 继承 Father,Child 可以使用父类的
protected的方法,但是 Brother 不能通过Child 使用Child的父类
Father方法,总的说来,就是除了继承可以使用protected父类的方法外,
都不可以使用protected。
有点绕口。。。。。。
1、同一包中,都可以访问;
2、不同包中,只有 public可以访问;
而public protected default private 修饰方法和变量。
1、public 同一包和不同包的类,都可以访问。private 只有类自己可以访问;
2、友好类和protected
a、在同一包中,不管子类还是其他类,都可以访问;
b、在不同包中,不管子类还是其他类,都不可以访问;
3、友好类和protected 区别,是在不同包中的继承方面;
a、不同包中,只有 protected 被子类使用,友好类是不可以被子类使用的;
b、假设 (Father Child Brother) Child和Brother 在同一个包中,
Father 自己在一个包中,Child 继承 Father,Child 可以使用父类的
protected的方法,但是 Brother 不能通过Child 使用Child的父类
Father方法,总的说来,就是除了继承可以使用protected父类的方法外,
都不可以使用protected。
有点绕口。。。。。。