Four access modifiers and their levels

serial number access level access modifier similar  Same package Subclass different packages
1 public public Can   Can Can Can
2 be protected protected Can Can Can Can't
3 default no access modifier Can Can Can't Can't
4 private private Can Can't Can't Can't

The difference between global variables and local variables
1.
Scope The scope of member variables is in the entire class
. Local variables start from where they are declared and
end where they are located.

2. Initial value
Member variables have an initial value (also called default value, also
called default value). Local variables have no initial value and must be declared and assigned
before use. 3. Modifiers Member variables can use modifiers such as public statc modify



Local variables cannot be
modified with modifiers such as public statc. If you want to use modifiers, you can only use final modifiers

A variable modified by final can only be assigned once, and
its value cannot be modified after the assignment is completed. This variable is called a
constant

final can modify member variables, but when final modifying
member variables, the member variables must be explicitly assigned

Guess you like

Origin blog.csdn.net/weixin_52682014/article/details/127561742