what is the difference between `public class` and

2019-01-31 00:43发布

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 when I don't declare a class as public, private or protected. But it works fine. What is the reason?

标签: java class
7条回答
做自己的国王
2楼-- · 2019-01-31 01:47

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;
}
查看更多
登录 后发表回答