Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use java non-access control modifiers

Shulou Source: shulou.com Published: 2022-05-31 10:53:15 11月12日 Update

This article mainly introduces the relevant knowledge of how to use java non-access control modifiers, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this article on how to use java non-access control modifiers. Let's take a look.

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;}} this is the end of the article on "how to use java non-access control modifiers". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use java non-access control modifiers". If you want to learn more, you are welcome to follow the industry information channel.

Tags: Variable control method code instance knowledge content again place article error static ordinary value hello constant member easy to operate article easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Xiaomi Microsoft NVidia MariaDB