How to use java non-access control modifiers
This article mainly introduces "how to use java non-access control modifiers". In daily operation, I believe many people have doubts about how to use java non-access control modifiers. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods, hoping to help you answer the doubts about "how to use java non-access control modifiers"! Next, please follow the editor to study!
1. The static modifier is used to modify methods and class variables.
2. Final decorators are used for decorations, methods, and variables.
The category of final decoration cannot be inherited, and the method of decoration cannot be redefined. Decorated variables are constant and cannot be modified.
3. Abstract modifier, used to create abstract and abstract methods.
4. The synchronized and volatile modifiers are mainly used for programming threads.
Example
Public class Test {/ / initialize values final String f = "Hello"; static final String w = "Hello" when defining variables; / / variables modified by final must show initialization static final int a; final int b; final int c; / / initialize static {a = 100 in a static code block / / instance variable / / bread15 cannot be initialized in static code block;} / / initialize {b = 100;} / initialize public Test (int c) {this.c = c in constructor } / / member variables can only be initialized in the above places, so final-modified variables can only be initialized / / initialized in these places. These statements will no longer execute public static void main (String args []) {/ / final-modified variables after their initial values are assigned for the first time, and cannot change / / assign values to final variables again An error will occur. / / Test.a=1000; Test test = new Test (80); System. Out.println (test.c); / / assign a value to the instance variable modified by final again, there will be an error / / test.c=60;}}, and the study on "how to use the java non-access control modifier" is over, hoping to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!