What is the function of static keyword in java

王林
Release: 2020-07-30 17:04:22
forward
2230 people have browsed it

What is the function of static keyword in java

Function:

(Recommended tutorial: java introductory tutorial)

(1) Static variables: also known as classes Variable, that is to say, this variable belongs to the class. All instances of the class share static variables and can be accessed directly through the class name. There is only one copy of static variables in memory;

(2) Static method: Static method exists when the class is loaded, and it does not depend on any instance. So the static method must have an implementation, which means it cannot be an abstract method. Only static fields and static methods of the class can be accessed, and the this and super keywords cannot be included in the method;

(3) Static statement block: The static statement block is run once during class initialization;

(4) Static inner classes: Non-static inner classes depend on instances of outer classes, while static inner classes do not. Static inner classes cannot access non-static variables and methods of outer classes;

(5) Initialization sequence: static variables and static statement blocks take precedence over instance variables and ordinary statement blocks, and static variables and static statement blocks are initialized The order depends on their order in the code.

(Video tutorial recommendation: java video tutorial)

Code example:

What is the function of static keyword in java

Output result:

What is the function of static keyword in java

The above is the detailed content of What is the function of static keyword in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!