Access Rights
In this lesson, we'll learn about access rights of inheritance.
We'll cover the following
Scope of access rights
The access rights of the inheritance determine which functionalities of the base class can be used in the derived class.
- A class can be derived
public
,protected
, orprivate
from its base class. - For classes, the default access right is
private
; for structs, it’spublic
.
class BankAcc: Acc{...}
is the same as class BankAcc: private Acc{...}
Is-a relations
The derived class and the base class have an is-a relationship. Public inheritance is called an is-a relationship because the derived class has the same interface as the base class. The derived class is a specialization of the base class.
public
class BankAccount: public Account{ ...
public
and protected
members in the Account class are public
and protected
in the BankAccount class.
protected
class BankAccount: protected Account{ ...
public
and protected
members in the Account class are protected
in the BankAccount class.
private
class BankAccount: private Account{ ...
public
and protected
members in the Account class are private
in the BankAccount.
In the next lesson, we’ll look at the examples of inheritance.
Get hands-on with 1200+ tech skills courses.