What is the difference between public, private, and protected?

后端 未结 17 1890
抹茶落季
抹茶落季 2020-11-21 07:54

When and why should I use public, private, and protected functions and variables inside a class? What is the difference between them?<

17条回答
  •  深忆病人
    2020-11-21 08:24

    private - can be accessed from WITHIN the class only

    protected - can be accessed from WITHIN the class and INHERITING classes

    public - can be accessed from code OUTSIDE the class as well

    This applies to functions as well as variables.

提交回复
热议问题