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

前端 未结 8 1348
说谎
说谎 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:48

    For declarations of classes are avaible only two keywords:

    • public .Example: public class Student{//...}
    • private package(as default) .Example: class Note{//...} .It is visible only in his package.

    You can use private and protected only if you declare an member inside of a class. Example:

    public class Student{
    protected Note note;
    }
    

提交回复
热议问题