The internal class that is "wow" (2) ----- the internal class accesses the peripheral class

Source: Internet
Author: User

Why can internal classes access members of peripheral classes? This is a very basic problem, but it is basically a basic issue. It is really important to solve the problem urgently. Because you do not understand this problem, there will be a lot of troubles for internal classes. The internal class can access the peripheral class because the internal class has a reference pointing to the peripheral class object. Because the creation of internal classes requires the creation of peripheral class instances first, the internal class is equivalent to the peripheral class method at the peripheral class composition level. But more importantly, the internal class can access all the members of the peripheral class, including the private one. As mentioned above, because the internal class must first create an instance of the peripheral class and obtain its reference when it is created, naturally, all the members of the peripheral class are open to the internal class. What evidence can prove it? The evidence is that we can return the reference of the peripheral class in the internal class, such as outerclass. This. However, if we only use. This, then the return is just a reference of the internal class. Since it can be returned from the internal class, it naturally indicates that the internal class has reference to the peripheral class, and there is no reference to it, right?

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.