java keyword

1. static

static is a very important keyword in java, and its usage is also very rich, there are four main usages:

  1. It is used to modify the member variable and turn it into a member of the class, so as to realize the sharing of this member by all objects;
  2. It is used to modify a member method and turn it into a class method, which can be called directly using the method of "class name.method name" , which is often used in tool classes;
  3. Static block usage, initializing multiple class members together makes the program more regular, and it is very important to understand the initialization process of objects;
  4. Static import package usage, import the method of the class directly into the current class, so that the class method can be called directly using the "method name" , which is more convenient

Guess you like

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