Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use java non-access control modifiers

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report