How to use the static modifier in java
Most people do not understand the knowledge points of this article "how to use the static modifier in java", so the editor summarizes the following content, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to use the static modifier in java" article.
1. The static keyword is used to declare static variables independent of the object. No matter how many objects a class instantiates, its static variable has only one copy. Static variables are also called class variables. Local variables cannot be declared as static variables.
2. The static keyword is used to declare static methods independent of the object.
Example
Class InstanceCounter {private static int num = 540; / / Private static variable public static int getNum () {/ / Public static method return num;} / / the constructor can automatically execute the constructor using the same public InstanceCounter () {System.out.println (this.getNum ()) in this as in es6. / / this.getNum () = = getNum () this.num++; / / this.num = = num}} public class demo1 {public static void main (String [] args) {new InstanceCounter (); System.out.println (InstanceCounter.getNum ()) / / print static method class name call 541}} the above is about "how to use static modifiers in java". I believe you all have some understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.