标签:int sub package pretty public end prot 子类 pack
1. private:在类或对象内部可见
class Outer{
class Inner
{
private def f(){println("f")}
class InnerMost{f()} //正确,在类Inner内
}
(new Inner).f() //错误,不在Inner类内
}
2.protected:子类中可见
package p
{
class Super{ protected def f() {println("f")}}
class Sub extends Super{f()}//正确,子类
class Other{(new Super).f()}//错误
}
3.public:所有地方可见
4.作用域保护 private[x] 或者protected[x]
标签:int sub package pretty public end prot 子类 pack
原文地址:https://www.cnblogs.com/hapyygril/p/11518676.html