What is the default access specifier for a base class when inheriting in C++?
A. private
B. public
C. protected
D. friend
Answer: Option A
Solution (By Examveda Team)
The correct answer is A: private.Let's break down why:
In C++, when you inherit a class without explicitly specifying an access specifier (like `public`, `private`, or `protected`), the default access specifier depends on how you inherit.
If you use the `class` keyword to derive a class, the default access specifier is private.
For example, if you write `class Derived : Base`, it's the same as writing `class Derived : private Base`.
If you use the `struct` keyword to derive a class, the default access specifier is public.
This means that if you don't write `public`, `protected`, or `private` before the base class name in the inheritance, the members of the base class become `private` in the derived class (when inheriting with `class`).
Therefore, the default access specifier is private.
Join The Discussion
Comments (1)
Related Questions on Inheritance in C plus plus
A. Multilevel inheritance
B. Hierarchical inheritance
C. Multiple inheritance
D. Single inheritance
A. public
B. private
C. friend
D. protected
What is the process of defining a new class based on an existing class in C++ called?
A. Inheritance
B. Composition
C. Encapsulation
D. Polymorphism

Answer A will be correct not C