+ 3

What is the use of the concept inheritance ?

30th Apr 2017, 2:34 AM
MOHANRAJ D
MOHANRAJ D - avatar
3 Antworten
+ 8
to create one class that can be use for other classes
30th Apr 2017, 2:37 AM
chris
chris - avatar
+ 3
Inheritance is when an object or class is based on another object (prototypal inheritance) or class (class-based inheritance), using the same implementation (inheriting from an object or class) or specifying a new implementation to maintain the same behavior (realizing an interface; inheriting behavior; programming by difference)
30th Apr 2017, 2:40 AM
⏩▶Clau◀⏪
⏩▶Clau◀⏪ - avatar
0
If you are going to use some set of variables and/or methods/functions in several places throughout the program, you will not get headache writing the same thing over and over. You will create a base class and then #include it in other class files, and if you need, add more members as well in the derived class. For example, Create a class Dog, which has common attributes, such as feet, head, ears, etc; then class Pitbull will inherit those attributes PLUS some specific attributes for itself. By the way, You can use the latter class as a base class to specify, let's say, HisPitbull class, also adding more details, if needed.
7th May 2017, 2:55 AM
Andranik Baghdasaryan
Andranik Baghdasaryan - avatar