Let's say we have three classes "A", "B" and "C". Can "C" class inherit from both "A & B" classes? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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
į Œį ŒBrains[Abidemi]
į Œį ŒBrains[Abidemi] - 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
į Œį ŒBrains[Abidemi]
į Œį ŒBrains[Abidemi] - 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