Global variable: Also called a member variable, refers to a variable defined in a class; it works in the entire class.
Global variables can also be divided into: class variables and instance variables
1. Class variables: Also known as static variables are modified with static it can be called directly with the class name can also be called with the object and all objects of the same class variable is shared with the same block of memory space
2. Instance variable: Without static decoration It can only be called through an object and the same instance variable of all objects is shared with different memory spaces
Local variables: Refers to the variables that are defined in the method body and the parameters of the method that are valid only within the method that defines it
Note: If the name of a local variable in a method is the same as the name of a global variable, the global variable is temporarily invalidated in this method
Global variables and local variables in Java