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

前端 未结 8 1349
说谎
说谎 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条回答
  •  旧时难觅i
    2020-12-12 18:46

    No a normal class and a public class don't work the same .A class without a access modifier such as public is automatically set to default access.(No, you can't give default as access explicitly). If you create a default access class inside a package then that class cannot be accessed outside that package but public class can be accessed even outside that package

提交回复
热议问题