Can 1 derive class have multiple base class? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can 1 derive class have multiple base class?

20th Jun 2016, 4:48 AM
Utpal Kumar
Utpal Kumar - avatar
3 Answers
+ 2
It can. Though, there's some disagreement in the professional and the academic community, if it should be allowed to have inheritance from multiple classes with implementation details as fields or method implementations (this can lead to conflicts, name shadowing etc.) In contrast, interface classes are universally accepted as they only declare pure virtual functions. Also this is why the creator of Java has decided to only allow interfaces to be inherited apart from one class with implementation details (up to Java 8 which breaks with the rule that persisted since version 1)
20th Jun 2016, 12:37 PM
Stefan
Stefan - avatar
+ 2
in C++ it is allowed, but in java (superior object oriented language than C++) it is not allowed. SIMPLE REASON: //Consider a parent class ParentA as follows class ParentA{ public: printValue(){ some code; } } //Consider a parent class ParentB as follows class ParentB{ public: printValue(){ //some code; } } //Consider a child class Child as follows class Child: ParentB, ParentA{ } If we try to call a "printValue()" method using "Child" class object, it is confusing which class's method should be called.
11th Jul 2016, 7:53 AM
Suraj Bobade
Suraj Bobade - avatar
- 2
I think it should be!
20th Jun 2016, 4:49 AM
Utpal Kumar
Utpal Kumar - avatar