Inheritance in C++

Inheritance is an important key feature of OOP's. In inheritance one class can inherit important data and functions of another class. It increases the re-usability of program code. it means, once the program is created, it can be directly used in other programs up to several times. Inheritance can also represent objects of real world and their relationships. 

इनहेरिटेंस OOP’s का एक महत्वपूर्ण की फीचर है। इनहेरिटेंस में एक क्लास द्वारा दूसरी क्लास के महत्वपूर्ण डाटा एवं फंक्शन को विरासत में प्राप्त किया जाता है। यह प्रोग्राम कोड के पुनः प्रयोग को बढ़ावा देता है अर्थात एक प्रोग्राम पूर्ण रूप से तैयार होने के पश्चात् कई प्रोग्राम में सीधे प्रयुक्त किया जा सकता है। इनहेरिटेंस वास्तविक दुनिया के ऑब्जेक्ट एवं उनके मध्य संबंधो को भी व्यक्त करता है।
Example:- Vehicle Class Inheritance (व्हीकल क्लास का इनहेरिटेंस)


Base/Super Class:The class whose properties are inherited by another class is called Base Class or Super class.

वह क्लास जिसकी विशेषताओ को अन्य क्लास द्वारा इन्हेरिट (विरासत) किया जाता है बेस क्लास या सुपर क्लास कहलाती है। 

Derived/Sub Class: The class that inherits properties from another class is called Derived Class or Sub class.

वह क्लास जो अन्य क्लास की विशेषताओ को इन्हेरिट (विरासत) करती है डीराईव्ड क्लास या सब क्लास कहलाती है। 

Types of Inheritance in C++ :-

Generally, there are five types of inheritance (सामान्यतः यह पांच प्रकार का होता है)-

a.) Single Inheritance(सिंगल इनहेरिटेंस):- 
In single inheritance, a class is allowed to inherit properties of only one class. It means, one sub class inherits one super class only.

सिंगल इनहेरिटेंस में एक क्लास, केवल एक अन्य क्लास की विशेषताओं को विरासत में प्राप्त (इन्हेरिट) कर सकती है अर्थात एक सब क्लास केवल एक सुपर क्लास को इन्हेरिट कर सकती है।












b.) Multiple inheritance (मल्टीप्ल इनहेरिटेंस):- 
In Multiple Inheritance, a class can inherit two or more classes. It means, one sub class inherits two or more super classes.

मल्टीप्ल इनहेरिटेंस में एक क्लास, दो या दो से अधिक अन्य क्लासेस की विशेषताओं को विरासत में प्राप्त (इन्हेरिट) कर सकती है अर्थात एक सब क्लास दो या दो से अधिक सुपर क्लास को इन्हेरिट कर सकती है।











c.) Multilevel inheritance (मल्टीलेवल इनहेरिटेंस):-
In multilevel inheritance, a class B inherits properties of super class A and class C inherits properties of intermediate base class/derived class B. It means, a sub class is formed by another sub class.

मल्टीलेवल इनहेरिटेंस में एक क्लास B, सुपर क्लास A की विशेषताओं को विरासत में प्राप्त (इन्हेरिट) करती है एवं एक क्लास C, इंटरमीडिएट बेस क्लास/डीराईव्ड क्लास B की विशेषताओं को विरासत में प्राप्त (इन्हेरिट) करती है अर्थात एक सब क्लास को दूसरी सब क्लास से तैयार किया जाता है।












d.) Hierarchical inheritance (हाईरारकीकल इनहेरिटेंस):- 
In Hierarchical inheritance, properties of a single base class are inherited by two or more derived class. It means two or more sub class is formed by a single super class.

हाईरारकीकल इनहेरिटेंस में एक बेस क्लास की विशेषताओं को दो या दो से अधिक डीराईव्ड क्लासेस विरासत में प्राप्त (इन्हेरिट) करती है अर्थात दो या दो से अधिक सब क्लासेस को एक सुपर क्लास से तैयार किया जाता है।











e.) Hybrid inheritance (हाइब्रिड इनहेरिटेंस):- 
Hybrid Inheritance is implemented by the combination of two or more type of inheritance (single, multiple, multilevel, hierarchical inheritance). 

हाइब्रिड इनहेरिटेंस को दो या दो से अधिक प्रकार के इनहेरिटेंस (सिंगल,मल्टीप्ल,मल्टीलेवल,  हाईरारकीकल इनहेरिटेंस) के संयोग से तैयार किया जाता है।




No comments:

Post a Comment