Class:
There are several modifiers for classes in Java: Private, Default (package), protect, public, and the following table:
| Range |
Private |
Default |
Protected |
Public |
| The same class |
√ |
√ |
√ |
√ |
| Classes in the same package |
|
√ |
√ |
√ |
| Classes in the same package, subclasses in different packages |
|
|
√ |
√ |
| All |
|
|
|
√ |
Add: There are final, and abstract modifiers:
The final decorated class cannot be inherited, and there are no subclasses.
An abstract-decorated class cannot be instantiated and must inherit from the quilt class. A class must be an abstract class as long as it has an abstract method, but an abstract class does not have to have an abstract method.
Variable:
1, there is 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 variable in the method cannot have an access modifier.
3, class variable modifiers private, default (package), protect, public, and the scope of the class is the same, the following highlights several other:
| modifiers |
| name |
Description |
Notes |
| Static |
Static variables (also called class variables, others are called instance variables) |
Can be shared by all instances of the class. You do not need to create an instance of a class to access static variables |
| Final |
constants, values can be assigned only once, and cannot be changed |
Be careful not to use const, although it can be used with static as the Const keyword in C and C + + to avoid maintaining a copy of each instance of the class |
| Transient |
Tells the compiler that this variable does not need to be persisted when the class object is serialized |
The main reason is that the amount of change can come through other variables, using it for performance problems |
| Volatile |
Indicates that multiple threads may modify this variable, requiring compiler optimizations to ensure that modifications to this variable are handled correctly |
|
Interface:
Public is generally used.
Part excerpt from:
http://www.bokee.net/bloggermodule/blog_viewblog.do?id=110495
Method: The modifiers and variables of the method are almost the same.