Why can a class implement multiple interfaces but not inherit from multiple classes in many languages?
Last updated
Interfaces declare only a contract (method signatures, no state), so implementing several with the same method still means defining just one method.
Classes carry state and implementation, so multiple class inheritance causes the diamond problem: ambiguity over which parent's method or field the child gets.
Java
defaultmethods reintroduce mild conflicts, resolved by forcing an explicit override. C++ allows multiple class inheritance but needs virtual inheritance to tame the diamond.
- https://www.baeldung.com/java-implements-vs-extends
- https://www.geeksforgeeks.org/java/why-java-doesnt-support-multiple-inheritance/
- https://www.geeksforgeeks.org/java/diamond-problem-in-java/
- https://medium.com/@aravindcsebe/the-diamond-problem-in-java-understanding-multiple-inheritance-conflicts-and-how-java-solves-them-343752ab7b40