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

java:访问权限-protected实例

相关文章:

  • 2022-12-23
  • 2021-07-13
  • 2021-08-04
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2021-05-04
  • 2022-12-23
猜你喜欢
  • 2022-01-10
  • 2021-12-12
  • 2022-12-23
  • 2022-01-03
  • 2021-09-19
相关资源
相似解决方案