在不同包,子类继承后可以使用父类的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(); } }