Skip to main content

Effect of derivation types on class members

Short answer

Derivation mode (public, protected, private) determines how base members are inherited: public derivation keeps public as public; protected makes both public and protected into protected; private makes them private. Inheritance types: single, multiple, multilevel, hierarchical, hybrid.

How do different types of derivation affect the members of class? Write down the types of inheritance.

Effect of the type of derivation

The derivation mode (public, protected, private) decides how the base class members are seen in the derived class and outside it. Private members of the base are never directly accessible in the derived class in any mode.

Base memberpublic derivationprotected derivationprivate derivation
publicpublicprotectedprivate
protectedprotectedprotectedprivate
privatenot accessiblenot accessiblenot accessible
  • Public: "is-a" relation; the public interface of the base remains public.
  • Protected: base public and protected members become protected, usable only in the derived class and its children.
  • Private: all accessible base members become private in the derived class (the default for class).

Example: class D : public B {}; keeps B's public members public in D.

Types of inheritance

  1. Single - one base, one derived class: A -> B.
  2. Multiple - a derived class has two or more base classes: A, B -> C.
  3. Multilevel - a chain: A -> B -> C.
  4. Hierarchical - several derived classes from one base: A -> B, A -> C.
  5. Hybrid - a combination of the above (e.g. diamond).

✓ Answer checked by Claude Opus 5.5 (high effort)

All Object Oriented Programming chapter 6 questions →