CSE2305 - Object-Oriented Software Engineering
Self Assessment Questions
For each question choose the single response which best answers the question, or which completes the statement most accurately.
| Question 30: | What is "polymorphism"? |
| When a given stimulus produces a unique response depending on the type of object stimulated |
| When a unique stimulus produces a common response for all objects stimulated |
| When the compiler determines the unique response to a stimulus, based on the type of the object stimulated |
| When the user determines a given response to a stimulus, by selecting the type of object which is stimulated |
| When a T-1000 terminator morphs itself into a giant parrot |
| Question 31: | How does polymorphism relate to abstraction? |
| Polymorphism is a mechanism for abstraction of functionality |
| Polymorphism is a mechanism for abstraction of structure |
| Polymorphism is a mechanism for abstraction of naming |
| All forms of abstraction are polymorphic |
| There is no relationship between polymorphism and abstraction |
| Question 32: | How does polymorphism relate to inheritance? |
| Polymorphism relies on inheritance to ensure that derived classes have the necessary capacity to receive a particular stimulus |
| Polymorphism relies on inheritance to ensure that no two classes respond identically to a particular stimulus |
| Polymorphism is the same as inheritance. The two concepts are identical |
| Polymorphism is the opposite of inheritance. The two concepts are mutually exclusive |
| There is no relationship between polymorphism and abstraction |
| Question 33: | What is "dynamic dispatch"? |
| When the function to be executed in response to a function call is determined very quickly (also known as "in-lining"). |
| When the function to be executed in response to a function call is determined at run-time. |
| When the function to be executed in response to a function call is determined at compile-time. |
| When the function to be executed in response to a function call is executed at compile-time. |
| When the function to be executed in response to a function call is determined at the end of the function call. |
| Question 34: | Why is it possible in C++ to make a base-class pointer point to a derived-class object |
| Because a derived-class object has all the properties (data and functions) of a base-class object, so it can be treated just like one for all intents and purposes (including being pointed at) |
| Because the compiler can automatically convert any base-class object to any required derived class |
| Because pointers in C++ aren't type-checked |
| All of the above |
| None of the above |
| Question 35: | If the pointer p is a pointer to a base class (B), but actually points to an object of a derived class (D), which member function gets called when the call p->Print() is executed? |
| B::Print() |
| D::Print() |
| B::Print() if B::Print() is not virtual, D::Print() if B::Print() is virtual |
| D::Print() if B::Print() is not virtual, B::Print() if B::Print() is virtual |
| Neither. The compiler flags it as an ambiguous case. |
| Question 36: | If a member function (void B::Reset(void)) is virtual in a base class B, which of the following declarations make the function D::Reset() non-virtual in the derived class? |
| class D : public B { static void Reset(void); }; |
| class D : public B { !virtual void Reset(void); }; |
| class D : public B { ~virtual void Reset(void); }; |
| class D : public B { void Reset(void); }; // NO KEYWORD |
| None of them. Once a function is virtual in a base class, it stays virtual in every derived class. |
| Question 37: | Why can't the compiler "hard-code" direct calls to virtual functions? |
| Because hard-coding the function call would slow down compilation of the program too much |
| Because hard-coding the function call would slow down execution of the program too much |
| Because the correct function to call generally isn't known at compile-time |
| Because virtual functions are always called at compile-time so no run-time code is needed at all. |
| The compiler does hard-code direct calls to virtual functions |
| Question 38: | The compiler generally replaces a virtual function call with some code like: (*((baseptr->_vtab)[0]))(). Which of the following steps does that code not perform |
| Follows the baseptr pointer to the secret _vtab field of the object being pointed to |
| Checks to see that the _vtab pointer is not 0 |
| Goes to the first element of the virtual table pointed to be the _vtab field |
| Looks up the function pointed to by that first element |
| Calls that function |
| Question 39: | Why does a class's destructor sometimes have to be specified as virtual? |
| Because it may never be called |
| Because it may be called through a pointer (or reference) to a base class |
| Because it may be called through a pointer (or reference) to a derived class |
| Because it may be called at run-time |
| Destructors can't be made virtual |
Last updated: July 18, 2005