The purpose of this quiz is to give you a chance to focus your knowledge of advanced inheritance and polymorphism in C++.
TRUE ✓ | FALSE ✗ | The virtual keyword is used for both polymorphism and (some) multiple inheritance. | ||
---|---|---|---|---|
TRUE ✗ | FALSE ✓ | Multiple inheritance is a breeze: just list two ancestors and you are done. | ||
TRUE ✓ | FALSE ✗ | It is very applicable and necessary in real-world problems, too (see the hover-craft and how it is both a land and water vehicle). | ||
TRUE ✗ | FALSE ✓ | I try to multiply inherit something everyday. |
TRUE ✗ | FALSE ✓ | Inheritance applies to all member variables, methods, and friends. | ||
---|---|---|---|---|
TRUE ✓ | FALSE ✗ | This rule applies to operator functions, too. | ||
TRUE ✗ | FALSE ✓ | Function objects, however, cannot participate in inheritance at all. |
TRUE ✓ | FALSE ✗ | When inheriting from a base with a static data member, all derived classes share the same static member. |
---|
TRUE ✓ | FALSE ✗ | An abstract class is one which contains pure virtual method(s). | ||
---|---|---|---|---|
TRUE ✓ | FALSE ✗ | Pure virtual methods are methods with no definition. | ||
TRUE ✓ | FALSE ✗ | This is achieved by setting the prototype = 0. | ||
TRUE ✓ | FALSE ✗ | This says in effect "this method will never be defined" which would, of course, be impossible to call and so the compiler won't allow objects to exist of this class. | ||
TRUE ✓ | FALSE ✗ | We can, however, make pointers to non-abstract derivatives of the abstract class. |
TRUE ✓ | FALSE ✗ | Composition is a situation where one class has at least one data member which is of another class type. | ||
---|---|---|---|---|
TRUE ✓ | FALSE ✗ | This is known as the "HAS A" relationship in software engineering. | ||
TRUE ✓ | FALSE ✗ | Inheritance is a situation where one class is a more specific sub-group of another class. | ||
TRUE ✓ | FALSE ✗ | In software engineering, this is known as the "IS A" relationship. |
TRUE ✓ | FALSE ✗ | When inheriting, we normally use the inheritance mode public. | ||
---|---|---|---|---|
TRUE ✓ | FALSE ✗ | However, we can also substitute private or protected there. | ||
TRUE ✓ | FALSE ✗ | A private inheritance mode causes all parent members to be private members of the child when viewed from the child class' descendants or outside the hierarchy. | ||
TRUE ✗ | FALSE ✓ | Likewise, a protected inheritance mode causes all parent members to be protected members of the child when viewed from the child class' descendants or outside the hierarchy. | ||
TRUE ✓ | FALSE ✗ | Both of these can prove terribly troublesome and are often avoided. |
TRUE ✓ | FALSE ✗ | The actual type of object at the end of a polymorphic base pointer can be determined at run time. | ||
---|---|---|---|---|
TRUE ✓ | FALSE ✗ | To do so, we need to use either the typeof function or the dynamic_cast operator. | ||
TRUE ✓ | FALSE ✗ | The function is in the typeinfo library and returns a type_info structure. | ||
TRUE ✓ | FALSE ✗ | To identify the type, you can compare the return value of the type_info structure's name method to a string containing the name of the type you desire. | ||
TRUE ✗ | FALSE ✓ | Such names are just what you'd expect them to be and so this is an easy method of identification. | ||
TRUE ✓ | FALSE ✗ | When using dynamic_cast, though, you simply check if the result of the cast is nullptr or not. | ||
TRUE ✓ | FALSE ✗ | If it's nullptr, the object was NOT of the desired type. |