C # and Java access modifiers

Source: Internet
Author: User

Java

-----------------------------------------------

Access modifier description

-----------------------------------------------

Private can only be used within this class (visible)

A non-write modifier means that the member can access each other only within the same package

Protected is also within the same package access, the difference above is that: in addition to the same package, other packages of subclasses can also access

Public indicates that the member variables and methods are common and can be accessed under any circumstances

-----------------------------------------------Super Split Line-----------------------------------------------

C#

-----------------------------------------------

Access modifier description

-----------------------------------------------

Private, like Java, can be used only in this class.

Protected is not the same as Java, except that only subclasses can access

Internal can only be accessed in the current assembly

Protected internal is the only combination of a form that is accessed in the current assembly or its own subclass, similar to the one in Java

Protected public access is not restricted.

-----------------------------------------------

Special Note: In C # If the class internal members (methods, properties, fields, etc.) do not write any adornments Fuzeme think private;

The default is internal if the access modifier of the Class (class) is not written.

Assemblies can be understood as current projects, such as when building a 3-tier framework, a solution will have multiple projects (presentation layer, business logic layer, data access layer ...). ), you can use internal if you want to access only the current project.

* The base class has at least the same accessibility as the derived class.

C # and Java access modifiers

Related Article

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.