Explain what a base class access specifier is and how it aff
Explain what a base class access specifier is and how it affects inheritance.
Solution
Access Specifier:
=> Access specifiers are keywords in object-oriented languages that set the accessibility of classes, methods, and other members.
=>Access modifiers are a specific part of programming language syntax used to facilitate theencapsulation of components.
=> In C++, there are only three access modifiers.
C# extends the number of them to five.
while Java has four access modifiers,but three keywords for this purpose.
=> access specifiers in base class
a) public
b) private
c) protect
These 3 access specifiers can be used to determine how the derived class will access the properties derived from the base class.
The general syntax for inheritance is thus as given below:
class name-of-derived-class : access-specifier name-of-base-class
{
//body of derived class;
};
Inheritance:
Inheritance means getting something from the parent.
=>there are three different ways for classes to inherit from other classes: public, private, and protected.
the following syntax for inheritance:
class derived-name: public base-name
{
//body of class;
};
Example:
// Inherit from Base publicly
class Pub: public Base
{
};
// Inherit from Base privately
class Pri: private Base
{
};
// Inherit from Base protectedly
class Pro: protected Base
{
};
class Def: Base // Defaults to private inheritance
{
};
public inheritance:
public inheritance is very easy to understand. When you inherit a base class publicly, inherited public members stay public, and inherited protected members stay protected. Inherited private members, which were inaccessible because they were private in the base class, stay inaccessible.
private Inheritance:
In private inheritance all members from the base class are inherited as private. This means private members stay private, and protected and public members become private.
protected inheritance:
All the public and protected members of base class become protected members of derived class.

