Differences between private, protected, public, and internal in common interview questions

Source: Internet
Author: User

Private, protected, public, and internal

Private, protected, public, and internal

 

PrivateIt is completely private and can only be called in the class itself. It cannot be called outside the class or subclass, or inherit the private attributes and methods of the parent class.

 

ProtectedAlthough it can be seen by the outside world, it cannot be called by the outside world. It can be called only by itself and its own subclass (the attributes and methods of protected can be inherited and called by the quilt class ).

 

What private and protected have in common: No external access is allowed.

Differences between private and protected: The same class can be considered the same, but it is different in inheritance. Private cannot be accessed in a derived class, while protected can.

 

PublicAll classes and members are publicly available without restrictions.

InternalSame ApplicationProgramSet (in a project in vs. net, the project here refers to a separate project, rather than the entire solution) can be accessed.

Differences between public and internal: Public members can cross-assembly, but internal cannot. The same Assembly has the same effect.

 

Protected internal:Only this class and derived class can be accessed in the same application assembly.

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.