1. Modifier member Variable: Static variable with the statics modifier, and no static modifier called instance variable.
Instance variable: An object that belongs to an object that has one copy. When an object is created, it is initialized, there are multiple replicas, and the replicas owned by each object do not affect each other. stored in the heap.
Static variables: Static variables are shared by all objects and have only one copy in memory, which is initialized only when the class is first loaded.
Demo:
1 Public classSpike2 {3 Public Static voidMain (string[] args)4 {5Counter A =NewCounter ();6 System.out.println (A.increment ()); Output 07 System.out.println (A.anotherincrement ()); Output 28Counter B =NewCounter ();9 System.out.println (B.increment ()); //Output 2 Ten } One } A classCounter - { - Private Static intCount = 0; the Public intIncrement () - { - returncount++; return count and execute + + statement first - } + Public intanotherincrement () - { + return++count; A } at}
Java Object-oriented _static keywords