+ 3
Tell about inheritance in detail.
Inheritance is a major contributing topic in C++ OOPS .
3 Respostas
+ 29
that is you can add more sub classes... You can now add yourself as a class easily)
This is the basic concept. For syntax and types you can Google it.
+ 26
The capability of a class to derive properties and characteristics from another class is called inheritance. Just like it's original meaning!
Sub Class: The class that inherits properties from another class .
Super Class:The class whose properties are inherited by sub class.
Where do we use this
Consider your family. You need create a class for your dad, mom, brother. Eat(), work(), sleep() are the functions which will be same for all of the three classes.
Without inheritance.
If we create these classes avoiding inheritance then we have to write all of these functions in each of three classes.
1.Here in your code there is duplication of three functions.
2.Chances of errors are more. Imagine you forgot an 'e' for brother. 😂
To avoid these we use INHERITANCE
NOW....
Create a super class family and write these three functions in it and inherit the rest of the classes from the family class, then we can simply avoid the duplication of data and increase re-usability(that is you can add more Subcl