Data Member: Data members can be dividedStatic Member,Instance Member
Static Member: Static member variables are associated with the class and can be used as "common" variables in the class. They are not dependent on the existence of characteristic objects.Class Name adding operators and variable names for access
Instance Member: Instance member variables are associated with objects, and access to instance members depends on the existence of instances.
Function member (static method, instance method)
Static Method: Static methods do not belong to specific objects. Static methods can access static member variables,Static methods cannot directly access instance variables.,Static methods cannot directly call instance methods.Can be called indirectly. First, you need to create an instance of the class, and then call the instance method through this specific object, but you can call the static method.
Instance method: The execution of an instance method is associated with a specific object. Its execution requires the existence of an object,The instance method can directly access static variables and instance variables. The instance method can directly access the instance method and static method.
The access method of static methods adds variable names to some class name operators.When multiple instance objects exist, the memory does not copy each specific instance method, but all objects of the same class share a copy of each instance method.
Class Test
{
Int X;
Static int y;
Void F ()
{
X = 1; // correct, equivalent to this. x = 1
Y = 2; // test. y = 1
}
Static void g ()
{
X = 1; // error. You cannot access this. x static constructor. You can only access static members.
Y = 1; // correct
}
}
Static void main ()
{
Test T = new test ();
T. X = 1; // correct
T. y = 1; // error. You cannot access static members in a class instance.
Test. x = 1; // error. You cannot access non-static members by class.
Test. y = 1; // correct
}
}