Answer to Question #211836 in C++ for Hemambar

Question #211836

definition of inheritance, types of inheritance with different access specifiers. All the concepts should be illustrated with appropriate diagrams and example programs.


1
Expert's answer
2021-07-01T01:11:22-0400

Inheritance in child class can be described as inheriting the features and behaviour/properties from the parent class. Here, the class that contains these members is called the ​base class​ and the class that inherits these members from the base class is called the ​derived class ​of that base class​.

Access Modifiers

Following modifiers should be used at the time of creation of a derived class from a base class:

●    Public

●    Private

●    Protected

The ​public​ data members can be accessed by any of its child class as well as the class objects.

Private ​data members are inaccessible outside the class.

Protected ​data members can only be accessed by the derived classes but are inaccessible using the class objects.

 

Inheritance: Syntax

Inherited class can be defined as follows:

class derived_class_name :access_modifierbase_class_name {

       ----

       ----

};

 

Inheritance: Types

There are six types of inheritance:

●    Single Inheritance: ​Here, a child class is created from a single parent class.


●    Multi-level Inheritance: ​Here, there is a series of derived classes, which means a derived class is created from another derived class.


●    Multiple Inheritance: ​Here, a child class is created from more than one parent/base class.


●    Multipath Inheritance: ​In this type of inheritance, a derived class is createdfrom other derived classes and the same base class of other derived classes.


●    Hierarchical Inheritance: ​Here, ​more than one derived classes are createdfrom a single base class, and further, child classes act as parent classes formore than one child class.







Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS