Object-oriented Series 2 (encapsulation)

Source: Internet
Author: User

The simplest operation is required to implement a series of complex functions, which is a technical solution. A precision instrument, a household electrical appliance, and a Xiaomi mobile phone may be used or used. They are extremely complicated internally, using a variety of accessories, using a lot of principles and knowledge. We all share the same feeling: simple, convenient, and good! In the face of complicated things, we are able to use them freely through simple introductions, and even some of them can be self-taught. Why? This uses object-oriented encapsulation.

Object-oriented encapsulation is to encapsulate complex processing in a "box". functions can be easily implemented only with a few buttons or keyboards in the shell. Oh, it turns out so.

So how is object-oriented encapsulation implemented?

Object-oriented very cleverly sets a threshold-access limiters. It is through access toggle control of external direct access to objects, so as to avoid all activities like a glass room being visible to others.

The access modifier is like the key of the door and the secret of the mobile phone. If you use it well, you can ensure security. If you do not use it well, you can lock the door independently and do not want to enter your family.

Access modifiers include private, public, protected, internal, and protected internal.


The types cannot be defined as protected, private, and protected internal, because these modifiers do not make sense for the types contained in the namespace. Therefore, these modifiers can only be applied to Members. However, you can use these modifiers to define nested types (that is, classes contained in other types, because in this case, the types also have Member States. The following code is valid:

public class OuterClass {    protected class InnerClass    {       //etc.    }    // etc.}

If a nested type exists, the internal type can always access all members of the external type. Therefore, in the above code, the code in innerclass can access all members of 0uterciass, or even private members of 0utclass.



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.