multiple inheritance Flashcards
how to incorporate multiple inheritance in c++?
class A: public B1, public B2 {}
how do data members in interfaces work?
any data members in an interface are automatically public, static, and final (like constants)
how to incorporate multiple inheritance in java?
not possible for classes, but classes can have multiple interfaces (also interfaces can extend other interfaces)
what if 2 interfaces provide the same constant?
user will need to specify which version it is (X.NUM or Y.NUM)
what are 3 ways to simulate multiple inheritance in java?
1) interfaces
2) duplicate code (bad solution)
3) use limitation - insert objects lower into hierarchy, override methods we dont want (bad)
in c++, what happens if a subclass with 2 super classes A and B both have the same method? how to call one or the other?
need to call it explicitly:
C c;
c.B::foo();
- not a problem if method signatures are different
what the diamond problem?
say we have a hierarchy where A is a superclass of both B1 and B2, and C is a subclass of both B1 and B2:
then, c has 2 copies of A’s data
for the diamond problem with A, B1, B2, and C, how to call B1’s version of a protected field “a”?
BA::a = 6;
in the diamond problem for C++, what if i dont want 2 copies of A in C?
inherit A virtually in B1 and B2:
class B1: public virtual A{…}
- now C is responsible for creating A’s members in C