---
title: "Access specifiers in inheritance"
subject: "Object Oriented Programming"
chapter: 6
key: "semester_3/object_oriented_programming:access-specifiers-inheritance"
source: https://www.bctengineer.com/q/semester_3/object_oriented_programming/access-specifiers-inheritance
site: BCT Engineering
---

# Access specifiers in inheritance

Object Oriented Programming · Chapter 6: Inheritance

- Asked in: 2068 Baisakh, 2 marks
- Video: [public, private, and protected Inheritance in C++](https://www.youtube.com/watch?v=kPIcAy0WEvE) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_3/object_oriented_programming/access-specifiers-inheritance
- Whole chapter: https://www.bctengineer.com/md/semester_3/object_oriented_programming/chapter-6

## Question

Explain different types of access specifiers used in inheritance.

## Short answer

Access specifiers private, protected, and public control class member access, and inheritance mode further changes accessibility: public inheritance preserves access; protected lowers public to protected; private makes all inherited members private. Private base members remain hidden in derived classes.

## Answer

C++ has three access specifiers that control how class members can be accessed, and also how they are inherited:

- **private** - accessible only inside the class itself (and friends). In inheritance, private members of the base are not directly accessible in the derived class.
- **protected** - accessible inside the class and in its derived classes, but not from outside.
- **public** - accessible from anywhere.

When a class is inherited, the specifier used in the derivation (`public`, `protected`, `private`) changes the access of the inherited members:

| Base member | public derivation | protected derivation | private derivation |
|---|---|---|---|
| public | public | protected | private |
| protected | protected | protected | private |
| private | hidden | hidden | hidden |

Example: `class D : public B { };` keeps B's public members public in D, and its protected members protected.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. Which statement about protected members is correct?
   A. Accessible from anywhere
   B. Accessible only in the class itself and its friends, not in derived classes
   C. Accessible in the class and its derived classes, but not from outside
   D. Accessible only in derived classes
   Answer: C. Protected members are available inside the class and its derived classes but not to outside code. (Key point: Protected access)

2. With protected derivation, a public member of the base becomes what in the derived class?
   A. public
   B. private
   C. hidden
   D. protected
   Answer: D. Under protected derivation, base public and protected members both become protected. (Key point: Protected derivation table)

3. How are private members of the base treated in the derived class?
   A. Hidden, not directly accessible in any derivation mode
   B. Become public with public derivation
   C. Become protected
   D. Become private and accessible
   Answer: A. Private members are inherited but hidden from the derived class in all derivation modes. (Key point: Private base members)

## Related in Object Oriented Programming

- [Protected specifier; student/test/result program](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aprotected-three-class-program) — Object Oriented Programming, chapter 6

## Related in other subjects

- [Strowger subscriber access design approaches](https://www.bctengineer.com/question.md?key=semester_8%2Ftelecommunications%3Astrowger-subscriber-access) — Telecommunications, chapter 1
