what is the difference between `public class` and just `class`?

前端 未结 8 1320
说谎
说谎 2020-12-12 18:27

I have noticed that if don\'t write public before a class its works same as like a public class. I can\'t understand why so? It should show a error

8条回答
  •  醉梦人生
    2020-12-12 18:41

    I have noticed that if don't write public before a class its works same as like a public class.

    No it doesn't. Unless it's public, the class won't be visible to other code which isn't in the same package. The default accessibility (which can't be specified explicitly) is that a class (or other member) is only visible to other code within the same package.

    You should read the Java Language Specification section 6.6 and the Java Tutorial (Controlling Access to Members of a Class) for more details.

提交回复
热议问题