Non-Access Modifiers for Beginners Section 27

 

announcement notice

This official account is purely a personal public welfare official account! I just want to help all java beginners. The official account has a series of free resources for the majority of java beginners to learn by themselves! There is also a WeChat exchange group for everyone to learn and discuss! ! ! You can pay more attention! ! ! You can also leave a lot of comments on our articles and leave your valuable comments! ! !

one

non-access modifier

Java also provides many non-access modifiers in order to implement some other functions.

The static modifier is used to modify class methods and class variables.

The final modifier is used to modify classes, methods and variables. Final modified classes cannot be inherited, modified methods cannot be redefined by inherited classes, and modified variables are constants and cannot be modified.

The abstract modifier is used to create abstract classes and abstract methods.

The synchronized and volatile modifiers are mainly used for thread programming.


two

static modifier

Static variables : The static keyword is used to declare static variables independent of objects. No matter how many objects a class instantiates, there is only one copy of its static variables. Static variables are also known as class variables. Local variables cannot be declared as static variables.

Static method : The static keyword is used to declare a static method independent of the object. Static methods cannot use non-static variables of the class. Static methods get data from a parameter list and then compute the data.

Access to class variables and methods can be accessed directly using class name .variablename and class name .methodname

three

final modifier

final variables can be explicitly initialized and can only be initialized once. A reference to an object declared final cannot point to a different object. But the data in final objects can be changed. That is to say, the reference to the final object cannot be changed, but the value inside it can be changed.

The final modifier is usually used in conjunction with the static modifier to create class constants.



   Scan the code to follow ∣ there are troublemakers to detour


Long press, identify the QR code, and follow

Note: This official account is purely a personal public welfare official account!

There is no recruitment information for any training institutions! !

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324651886&siteId=291194637