Private, protected, public, partial

Source: Internet
Author: User

Private, Only the class can be accessed directly,
Protected, which can be accessed directly within the class and subclass,
Public, which can be accessed directly by anyone.
The inheritance type indicates the parent class.
Example:
Class {
Public:
Int A1;
Protected:
Int A2;
Private:
Int A3;
};
A;
A. A1; // OK
A. A2; // Error
A. A3; // Error
Class B: Public {
Public:
Void FB (){
A1; // OK
A2; // OK
A3; // error;
}
};
B;
B. a1, B. a2, B. a3 and. a1,. a2,. like A3, because it is Class B: Public A, it is equivalent to putting a to the public part of B.
For example
Class B:PrivateA {};
Then
B. A1, B. A2, and B. A3 all have errors, because it is equivalent to putting A to B'sPrivateIn part, from B, all three variables arePrivate.

PartialThe keyword is used to divide your class into multiple parts, and the compiler will combine multiple parts.
Example:
PublicPartialClass sampleclass
{
Public void methoda ()
{
}
}

PublicPartialClass sampleclass
{
Public void methodb ()
{
}
}

And

Public class sampleclass
{
Public void methoda ()
{
}
Public void methodb ()
{
}
}
Is equivalent.

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.