+ 4

Let's say we have three classes "A", "B" and "C". Can "C" class inherit from both "A & B" classes?

10th Dec 2017, 8:52 PM
Shawn Brown
Shawn Brown - avatar
7 Respostas
+ 12
No as multiple inheritance of classes is not allowed Edit: Sorry, I was mistaken, multiple inheritance is allowed in C++
10th Dec 2017, 8:54 PM
David Akhihiero
David Akhihiero - avatar
+ 9
It's allowed in C++ but it won't be meaningful if Cat class is inherited from class Dog, because a cat is not a dog. You can decide whether you should use Inheritance relationship or not by thinking of "IS-A" relationship. If "class A is a class B" makes sense, then B is the parent class and A is a child class of B. Let's consider the following statements: Animal is a Dog - ❌ Animal is a Cat - ❌ Dog is an Animal - ✅ Dog is a Cat - ❌ Cat is an Animal - ✅ Cat is a Dog - ❌ So, Animal should be the parent class and both Dog đŸ¶ and Cat đŸ± should be it's child classes.
11th Dec 2017, 4:02 AM
Shamima Yasmin
Shamima Yasmin - avatar
+ 6
yerucham he never told you it was in java😂😂
10th Dec 2017, 9:02 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 6
Oh boy
10th Dec 2017, 9:05 PM
David Akhihiero
David Akhihiero - avatar
+ 6
It's allowed in mandarin,a Chinese based half OOP language I guess
10th Dec 2017, 9:06 PM
᠌᠌Code X
᠌᠌Code X - avatar
+ 3
Thanks @Yerucham.
10th Dec 2017, 8:57 PM
Shawn Brown
Shawn Brown - avatar
+ 1
yes c++ support multiple inheritance while in java it isn't possible that's where interfaces come to play
12th Dec 2017, 6:32 AM
Muhammad Elzubairu
Muhammad Elzubairu - avatar