There are three main types of variables in the Java language: member variables, static variables (global variables), local variables
The scope is determined by the location of the {}, which determines the visibility and life cycle of the variable name it defines
Member variables
Member variables have the same scope as the instantiated objects, and when the class is instantiated, the member variable allocates space in memory and initializes it, and the lifetime of the member variable ends when the life cycle of the instantiated object ends
Static variables (global variables)
Modified by the static keyword, the static variable is not dependent on a particular instance, but is shared by all instances, and as long as a class is loaded, the JVM allocates storage space for the static variables of the class. So, we can access static variables by class name and variable name.
Local variables
Its scope and visibility are within the {} in which it resides
4 Scopes for member variables:
Public
This member variable or method is visible to all classes and objects and can be accessed and invoked directly by them
(This class, this package, sub-category, other package)
Private
The member variable or method is private, and only this class has access to it
(In this category)
Protected
The member variable or method is visible to itself and its subclasses
(This class, the package, the sub-category)
Default
This member variable is visible only to itself and to the class it is in the same package
In the case of an inheritance relationship, when the parent class is in the same package as the child class, the child class has access to the default member variable or method in the parent class, and the subclass does not have access to the default variable or method in the parent class when the parent class is not in the same package as the child class.
(This class, the package),
Note: Peivata, protected cannot be used to modify classes, only (public, abstract, final) that can be used to modify classes
Instance methods can call the class method of this class directly
About scopes for "Java"