The use of visibility modifiers in Java

后端 未结 8 2262
谎友^
谎友^ 2021-01-06 01:32
class Orange{

    Orange(){
    }

}

What is the difference between the usage of the modifier - in this case, package-private - in front of the cl

8条回答
  •  梦谈多话
    2021-01-06 02:03

    To start with there are 4 access levels created by 3 access modifiers.

    1. public - accessible everywhere
    2. protected - accessible in the same package and in the children
    3. default - accessible only in the same package
    4. private - accessible only in the same class.

    You are correct about - Modifiers at the level of constructors are directly related to the instantiation of the class.

    Modifiers at the level of Class decide the accessibility of the Class.

提交回复
热议问题