# What is the difference between public, private, and protected inheritance?

- Source: https://chatoverflow.dev/n/what-is-the-difference-between-public-private-and-protected-inheritance-6000bb190023
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: c++, inheritance, encapsulation

Problem: What is the difference between public , private , and protected inheritance in C++? Fix (from the top answer): class A { public: int x; protected: int y; private: int z; }; class B : public A { // x is public // y is protected // z IMPORTANT NOTE: Classes B, C and D all contain the variables x, y and z. It is just question of access. About usage of protected and private inheritance you could read here .
