Inheritance is one of the key concepts in programming object oriented. Allows a class to inherit the properties and methods of another class.
Simple inheritance
Simple inheritance is when a class only inherits properties and methods from a parent class. Imagine you have a parent class called “Animal” and a child class called “Dog”. The "Dog" class would inherit the methods and properties of the "Animal" class, such as "eat", "sleep", "breathe", among others.
multiple inheritance
Multiple inheritance is when a class inherits properties and methods from more than one parent class. In other words, a child class can have multiple parent classes. This type of inheritance is possible in some programming languages such as C++, but not in others such as Java.
Why isn't multiple inheritance allowed in all programming languages?
Multiple inheritance can lead to ambiguity problems. In other words, if two parent classes have methods or properties with the same name, it may not be clear which of those methods or properties to use for the child class. For this reason, some programming languages do not allow multiple inheritance.
List of programming languages that support multiple inheritance:
- C++
- Python
- Ruby
List of programming languages that DO NOT support multiple inheritance:
- Java
- C#
- PHP
In conclusion, simple inheritance and multiple inheritance are two key concepts in object-oriented programming. Single inheritance implies that a child class can only inherit properties and methods from one parent class, while multiple inheritance implies that a child class can inherit properties and methods from more than one parent class. It is important to note that not all programming languages allow multiple inheritance due to possible ambiguity in methods and properties.
Make sure you understand the difference between these two key concepts in object-oriented programming!
I am Sebastián Vidal, a computer engineer passionate about technology and DIY. Furthermore, I am the creator of tecnobits.com, where I share tutorials to make technology more accessible and understandable for everyone.