✔ 最佳答案
Scope defines how and where variables live in your program.
The simple ones are local and global variables, there is also static and extern.
- local lives within block level, e.g. within a pair of {}. Once the variable goes out of scope (closing braces), nobody can reference it. This is the most common use of variables.
- global is the opposite, it remains visible throughout the same program file. All methods within the same same file can reference global variables.
- static lives before a class object is instantiated. usage: ClassA.variable = 1; It is generally used for storing static values such as constants (values that never change) so references to the values is easy. Math.PI is a good example.
- extern is a hint to the program saying that the variable lives in the program, may not be in the same file.