java:访问权限-protected实例

在不同包,子类继承后可以使用父类的protect权限的属性或方法

父类:

package com.tinyphp;
public class Father
{
    protected String name;
}

子类:

package com.test;
import com.tinyphp.Father;
class Child extends Father
{
    void read(){
        name="tinyphp";
        System.out.println(name);
    }

}

调用:

package com.test;
class Test
{
    public static void main(String args[]){
        Child c = new Child();
        c.read();
    }
}

posted @ 2014-05-12 22:50  tinyphp  Views(1871)  Comments(0Edit  收藏  举报