Explain the difference between public, protected, and private inheritance.

Last updated 21 June 2026

  • The specifier caps base member visibility in the derived class: public preserves access, protected makes public/protected members protected, and private makes them private. Base private members are always inaccessible.

  • Only public inheritance ("is-a") allows implicit Derived*-to-Base* conversion and thus polymorphism. Protected/private model "implemented-in-terms-of" reuse.

  • The default is private for class and public for struct.

  • https://www.geeksforgeeks.org/cpp/visibility-modes-in-c-with-examples/
  • https://dev.to/master-rj/oop-in-c-explained-is-a-vs-has-a-relationship-inheritance-vs-composition-guide-g5o
All C++ interview questions