Public protected internal Private in C #

Source: Internet
Author: User

1. Common four azimuth modifier relationships
The protected internal is a relationship of the association, meaning that it is internal within the namespace and is protected outside the namespace.

2.sealed Final
The sealed modifier can be applied to classes, instances, methods, and properties. this is in C #.
  1. When used in a class, the class is called a sealed class, and the sealed class cannot be inherited;
  2. when used in a method, this method is called the sealing method, and the sealing method overrides the method in the base class; when the sealed modifier is applied to a method or property, must always be used with override ;
  3. Structures are implicitly sealed, so they cannot be inherited.

The final modifier qualifies variables, fields, methods, and classes. This is in Java.

    1. When used in a variable, the variable can only be assigned one time and cannot be modified;
    2. when used in a method, the method cannot be overridden or hidden;
    3. When used in a class, the class cannot be inherited.
    4. The members of an interface cannot use the keyword, and cannot use final as the abstract class.

It is worth mentioning that if you use a field in the final decorated class, the field must be assigned a value in the constructor, otherwise it is simply not possible to use the class instance invocation in such a way that the field can be assigned a value. when the class is instantiated, it assigns an initial value to each member field, and then if you invoke the final field again by instance, it is two times the assignment . , this situation is not allowed. The method of assigning a value to a final variable in a constructor is called "Delay Assignment" (Java), and the corresponding final variable is called "blank Final" (Java).

Final is not a keyword in C #, but often appears in C # interview questions, such as "Final, Finally, finalize the difference", in fact, this has gone beyond the category of C #, these three keywords examined J #,. Net fault-tolerant methods, respectively. NET garbage collection mechanism, oddly, every time I interview C # program personnel, most of the people to final this keyword is not unfamiliar with the sense, but the answer is well-reasoned, it seems that before the interview, early on the online preview, hehe.


 

From for notes (Wiz)

List of attachments
    • The access level of the modifier. png

Public protected internal Private in C #

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.