/**
* Created by rabbit on. Blog
* 1. static: static
* Usage: it is a modifier used to modify members (member variables, member functions ).
* When a member is statically modified, an additional call method is provided, except that the member can be called by an object,
* It can also be called directly by the class name. Format: Class Name. static member
*
* 2. static features
* 1. Loading with classes
* That is, the static state disappears with the disappearance of the class. It indicates that his life cycle is the longest.
*
* 2. takes precedence over object existence
* Static objects exist first and objects exist later.
*
* 3. shared by all objects
* 4. It can be directly called by the class name.
*
* 3. Differences between instance variables and class variables
* 1. storage location
* Class variables exist in the method area as the class is loaded,
* Instance variables exist in heap memory as objects are created.
* 2. Lifecycle
* The maximum lifecycle of a class variable disappears as the class disappears.
* The lifecycle of an instance variable disappears as the variable disappears.
*
* Iv. Static usage considerations
* 1. Static methods can only access static members. Non-static members can access static members,
* You can also access non-static members.
* 2. this and super keywords cannot be defined in static methods.
* Because the static state takes precedence over the object existence, the this and super keywords and,
*
* 5. Static advantages and disadvantages
* Benefits: the shared data of objects is stored separately to save space. You do not need to store one copy of each object.
* Can be called directly by Class Name
* Disadvantages: the lifecycle is too long,
* The usage has limitations. Static methods can only call static variables;
*
* Created by rabbit on. Blog
*/
Public class static_demo
{
String name; // member variable (instance variable)
Static String country = "CN"; // static member variable (class variable)
Public static void show ()
{
System. out. println (country + "method ");
}
}
// Created by rabbit on. Blog
Class demo_static
{
Public static void main (String [] args)
{
System. out. println (static_demo.country );
Static_demo.show ();
}
}
// Created by rabbit on. Blog