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-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

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

Development

Wechat

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

12
Report