Class:
In Java, class modifiers include private, default (package), protect, and public. Their scopes are as follows:
| Range |
Private |
Default |
Protected |
Public |
| Same class |
√ |
√ |
√ |
√ |
| Classes in the same package |
|
√ |
√ |
√ |
| Classes in the same package and subclasses in different packages |
|
|
√ |
√ |
| All |
|
|
|
√ |
Supplement: there are also final, and abstract modifiers:
The final-modified class cannot be inherited and has no subclass.
Abstract-modified classes cannot be instantiated and must be inherited by the quilt class. As long as a class has an abstract method, it must be an abstract class, but the abstract class does not have to have an abstract method.
Variable:
1. There are no global variables in Java, as long as the method variables, instance variables (non-static variables in the class), class variables (static variables in the class)
2. the variables in the method cannot have access modifiers.
3. The class variable modifier private, default (package), protect, public and class range are the same. The following describes the other types of variables:
| Modifier |
| Name |
Description |
Remarks |
| Static |
Static variables (also known as class variables and other variables called instance variables) |
Can be shared by all instances of the class. You do not need to create a class instance to access static variables. |
| Final |
Constant. The value can only be assigned once and cannot be changed. |
Do not use Const. Although it has the same meaning as the const keyword in C and C ++, it can be used together with static to avoid maintaining a copy for each instance of the class. |
| Transient |
Tells the compiler that this variable does not need to be permanently saved during class Object serialization. |
It is mainly because the amount of changes can be obtained through other variables, and it is used for performance problems. |
| Volatile |
It is pointed out that there may be multiple threads to modify this variable, and the compiler is required to optimize it to ensure that the modification of this variable can be correctly processed. |
|
Interface:
Public is generally used.
Part from:
Http://www.bokee.net/bloggermodule/blog_viewblog.do? Id = 110495
Method: The modifier of the method is similar to that of the variable.