Static keyword Knowledge point collation
Static Features:
1,static is a modifier that is used to decorate a member.
2,static decorated members are shared by all of the objects.
3,static takes precedence over the existence of an object because static members already exist as the class loads.
4,static decorated members have a way to call, can be directly called by the class name, (class name. static member).
5, statically decorated data is shared data, objects are stored in the unique data.
member variable = = Instance variable
Static variable = = Class variable
The difference between a member variable and a static variable
1, two variables have a different life cycle.
Member variables exist for the creation of objects and are freed as objects are recycled.
Static variables exist as the class loads, disappearing as the class disappears.
2, different calling methods
Member variables can only be called by an object.
A static variable can be called by an object and can also be called by a class name. (It is recommended to call with the class name)
3, different aliases
Member variables are also known as instance variables
Static variables are called class variables
4, the data is stored in different locations.
Member variable data is stored in the object of the heap memory, so it is also called the object's unique data.
Static variable data is stored in the static area of the method area (shared data area), so it is also called the shared data of the object
Considerations for static use
1, static methods can only access static members. (Non-static can access both static and non-static.) )
Cannot make a static reference to the Non-static field name
Non-static variables cannot be referenced in a static method name
2, the This or Super keyword cannot be used in a static method.
3, the main function is static
public class Test {int a =1;public static void Main (String [] args) {new Test (). Show (); public void Show () {System.out.println (a);}}
The main function is special:
1, the format is fixed.
2, recognized and invoked by the JVM
Java Static keyword