1. Inheritance:A Class A can inherit another class B, then we call Class B the base class (the parent Class), and Class A is a derived class (subclass). 2. Derived classes inherit all members from the base class, except constructors, destructors, and = functions. 3. Private members of the base class, although they are also private members of derived classes, cannot be accessed by member functions defined in the derived class. Private members of these base classes can only be accessed through the public member functions of the base class. 4. Subclasses can implement their own members of the same prototype as the parent class member functions (function name, parameter list)functions, called Overrides. Overrides are exceptions to function overloading, and overrides must occur in the process of inheritance. when calling the overridden parent version of a function in a subclass, add base to the function name:: (base class name base) such as point:: 5. Constructors in derived classes6. Protected:members modified by protected can only be accessed directly from the current class and its derived classes, and other classes or functions are still not visible. attached Source:
1#include <iostream>2 3 using namespacestd;4 classbase{5 Public:6Base (inti): B_number (i) {}7 intGet_number ()Const{returnB_number;}8 voidprint () {9cout<<b_number<<Endl;Ten } One //Private: A protected: - intB_number; - }; the classDerived: Publicbase{ - Public: -Derived (intIintj): Base (i), D_number (j) {} - voidprint () { + //cout<<get_number () << ""; -cout<<b_number<<" "; +cout<<d_number<<Endl; A } at Private: - intD_number; - }; - intMainintargcConst Char*argv[]) { -Base A (2); -Derived B (3,4); incout<<"a is"; - a.print (); tocout<<"b is"; + b.print (); -cout<<"base Part of the B is"; the b.base::p rint (); * return 0; $}
C + + Eighth day Note February 25, 2016 (Thursday) a.m.