--- Java training, Android training, IOS training, and. Net training. We look forward to communicating with you! ---
1. Basic concepts of Scope
Local variables and global variables have their own scopes, and member variables are no exception.
Scope: the scope within which access is allowed.
2. Scope type of member variables
@ Public can be directly accessed anywhere
@ Protected can be accessed directly in the implementation of the current class and subclass @ implementation. Only the set get method can be used for external access.
@ Private can only be accessed directly in the Implementation @ implementation of the current class. If the subclass wants to access the private variables in the parent class, it can only be accessed using the set get method.
@ Package can be accessed within the same "system" (framework), between @ private and @ public
The default scope is @ protected.
3. Supplement
1> @ implementation can also define member variables. The default scope is private (private)
2> member variables with the same name as @ interface cannot be defined in @ implementation.
3> NO @ interface. Only @ implementation can develop a class, but this is not recommended.
Black Horse programmer 02-scope of member variables