+ 3
What is the use of the concept inheritance ?
3 Respostas
+ 8
to create one class that can be use for other classes
+ 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)
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.