0
Can 1 derive class have multiple base class?
3 Antworten
+ 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)
+ 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.
- 2
I think it should be!