C # basic knowledge protected keywords

Source: Internet
Author: User
Class basetest {public int A = 10; protected int B = 2; protected void test () {}} class childtest: basetest {int C; int D; Public void printtest () {// The protected keyword is a member access modifier. A protected member can be accessed by a derived class instance in its class. // The protected member of the base class is only accessible in the derived class when access is made through the derived class. // => (1) access the console through base. writeline (base. a. tostring (); console. writeline (base. b. tostring (); // => (2) basetest = new basetest (); // equivalent to basetest basetest1 = new childtest (); console. writeline (basetest. a); // console. writeline (basetest. b); // inaccessible // => (3) include the class derived type childtest = new childtest (); console. writeline (childtest. a. tostring (); console. writeline (childtest. b. tostring ());}}

 

C # basic knowledge protected keywords

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.