Can I limit the methods another class can call in Java?

前端 未结 6 917
猫巷女王i
猫巷女王i 2020-12-11 15:01

Let\'s assume I have classes A, B, and C where class C has readable and writable properties:

public class         


        
6条回答
  •  生来不讨喜
    2020-12-11 15:31

    Java has 4 scopes: private, protected, public and "package". Something that is public can be accessed from anywhere. protected only from subclasses. private is only that class. "package" scope is not named, but if you omit any of the other three, it is assumed package scope. This is only accessible by other classes in the same package.

    HTH.

提交回复
热议问题