The change of visibility of object-oriented language member variable method in inheritance

Source: Internet
Author: User
Tags access properties

Recently done a little miscellaneous, exposure to several object-oriented language, C#,c++,java. In one scenario, the software framework has been written, and we want to add and modify its functionality, which is often happening, so what do we do in object-oriented program design? We all know that object-oriented language has several characteristics, polymorphism, encapsulation, inheritance, since the framework has been written, we modify the function can be considered to use the inherited method to implement the new function, then this will affect the original function? This involves the change in the visibility of member variable member methods in inheritance.

First, we look at C + +

Derived classes inherit the members of the base class as part of themselves, but different inheritance methods cause the members of the base class to have different properties in the derived class. We first use the access properties that represent that the base class member inherits after it will behave in a derived class:

is a single-inheritance approach and does not involve the derivation of derivations again. But both of these situations can be deduced using the logic of the diagram. As in the case of derivation again, it is possible to treat a derived class as a base class.

Here we already know the properties of the members in the base class in the inheriting class, and then we detail the visibility problem by an angle.

How to Inherit Public inheritance Protected inheritance Private inheritance
Base class member properties Public Protected Private Public Protected Private Public Protected Private
Base class members on their objects Visible Not visible Not visible Visible Not visible Not visible Visible Not visible Not visible
Base class members for derived classes Visible Visible Not visible Visible Visible Not visible Visible Visible Not visible
Base class member on derived class object Visible Not visible Not visible Not visible Not visible Not visible Not visible Not visible Not visible

The change of visibility of object-oriented language member variable method in inheritance

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.