View Assessment Result: Multiple Choice Quiz 5



Your performance was as follows:

1.
Polymorphism is a mechanism that is used in order to

(a) determine the type of an object dynamically at run time
(b) protect data members from illegal access
(c) build new classes on top of existing ones
(d) determine methods of a class based on its data members

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 1.5.1 of the course notes.
   (a) No Feedback



2.
What is composition?

(a) It is a method to build new classes on top of existing ones.
(b) It is an important idea in Object Oriented Programming, but currently it is not implemented in C++.
(c) It is the inclusion of one class in another as a data member.
(d) It is the same as polymorphism.

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 1.5.1 of the course notes.
   (c) No Feedback



3.
In which of the following situations would private inheritance be a sound choice?

(a) Whenever multiple inheritance is used
(b) When the base class is templated
(c) To derive a stack from a general linked list class
(d) To derive a numerical array class from a general one

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 1.5.1 of the course notes.
   (c) No Feedback



4.
Under what circumstances will a member function in C++ display polymorphic behavior?

(a) If and only if the class has multiple inheritance
(b) If and only if the class is not templated
(c) If and only if the function is explicitly declared to be virtual
(d) Always

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 1.5.1 of the course notes.
   (c) No Feedback



5.

Consider the following inheritance declarations.

      class Base    { public: int x; private int y; };
      class Derived: public Base  { public: int z; };
      Derived  D;

Under these declarations, which of the following statements, if any, will fail to compile?



(a) D.y = 555;
(b) D.z = 555;
(c) D.x = 555;
(d) None

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 1.5.1 of the course notes.
   (a) No Feedback



6.

Consider the following inheritance declarations.

    class Base { virtual  void f(int); virtual void f(float); };
    class Derived: public Base  { void f(int); };
    Derived  D;
    Base     B, *p = &D;

In the context of these declarations, the two functions that are used in the two calls D.f(3.1415); and p-f(3.1415); are, respectively,



(a) Base::f(double) and Derived::f(int)
(b) Derived::f(int) and Derived::f(int)
(c) Derived::f(int) and Base::f(double)
(d) Base::f(double) and Base::f(double)

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.5.1 of the course notes.
   (b) No Feedback



7.
Which of the following is true about a class without a (user-defined) constructor?

(a) It may have a destructor, but might not.
(b) It must have a destructor.
(c) It cannot have a destructor.
(d) It cannot have an assignment operator.

Correct answer is (a)

Your score on this question is: 10.00

Feedback:
   See section 1.5.1 of the course notes.
   (a) No Feedback



8.
Every class that is supposed to behave like a built-in type must overload which operator?

(a) The comma operator
(b) The output operator
(c) The assignment operator
(d) The call operator

Correct answer is (b)

Your score on this question is: 10.00

Feedback:
   See section 1.5.1 of the course notes.
   (b) No Feedback



9.
The proper tool for writing a linked list that can have some elements with ints and other elements with floats is the use of

(a) templates
(b) unions
(c) casting of ints to floats and the use of a simple list
(d) inheritance

Correct answer is (d)

Your score on this question is: 10.00

Feedback:
   See section 1.5.1 of the course notes.
   (d) No Feedback



10.
How should a copy constructor function in a linked list class?

(a) A linked list class should not have a copy constructor.
(b) It should copy only the list header, and not the nodes.
(c) It should copy all the nodes and the list header.
(d) It should copy the list header, but should copy the nodes only if there are less than four nodes.

Correct answer is (c)

Your score on this question is: 10.00

Feedback:
   See section 1.5.1 of the course notes.
   (c) No Feedback



Go to top of assessment.

Total score: 100.00