Black Horse programmer 02-scope of member variables

Source: Internet
Author: User

--- 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.