What Do You Know About C++ Polymorphism? Trivia Quiz

25 Questions | Total Attempts: 242

SettingsSettingsSettings
Please wait...
What Do You Know About C++ Polymorphism? Trivia Quiz

What do you know about C++ Polymorphism? C++ Polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function. Take up the quiz below and get to review what you got to understand from the classwork this past week. All the best!


Questions and Answers
  • 1. 
    Polymorphism enables you to:
    • A. 

      Program in the general.

    • B. 

      Program in the specific.

    • C. 

      Absorb attributes and behavior from previous classes.

    • D. 

      Hide information from the user.

  • 2. 
    Polymorphism specifically enables the creation of programs that handle:
    • A. 

      Classes that are containers for other classes

    • B. 

      Large amounts of data with efficiency

    • C. 

      A wide variety of classes in a general manner

    • D. 

      None of the above

  • 3. 
    When used correctly, polymorphism will never require changes to be made to any part of the program.
    • A. 

      True

    • B. 

      False

  • 4. 
    Polymorphism enables objects of different classes that are related by a class hierarchy to be processed generically.
    • A. 

      True

    • B. 

      False

  • 5. 
    Polymorphism allows for specifics to be dealt with during:
    • A. 

      Execution

    • B. 

      Compilation

    • C. 

      Programming

    • D. 

      Debugging

  • 6. 
    Polymorphism allows the addition of classes providing they were at least considered during program development.
    • A. 

      True

    • B. 

      False

  • 7. 
    Polymorphism allows you to command a wide variety of objects even if you do not know the objects' types.
    • A. 

      True

    • B. 

      False

  • 8. 
    Which statement best describes the relationship between the base class and derived class types?
    • A. 

      A derived class reference cannot be assigned to a base class variable and a base class reference cannot be assigned to a derived class variable.

    • B. 

      A derived class reference can be assigned to a base class variable and a base class reference can be assigned to a derived class variable.

    • C. 

      A base class reference can be assigned to a derived class variable, but a derived class reference cannot be assigned to a base class variable.

    • D. 

      A derived class reference can be assigned to a base class variable, but a base class reference cannot be assigned to a derived class variable.

  • 9. 
    If a derived class reference is assigned to a base class variable, the variable must be cast back to the derived class before any derived class methods can be called with it.
    • A. 

      True

    • B. 

      False

  • 10. 
    The abstract methods and properties of a class do not provide an implementation.
    • A. 

      True

    • B. 

      False

  • 11. 
    You may define implementations for abstract methods to act as default implementations.
    • A. 

      True

    • B. 

      False

  • 12. 
    An abstract base class can be used to declare references.
    • A. 

      True

    • B. 

      False

  • 13. 
    An abstract class may be derived from another abstract class.
    • A. 

      True

    • B. 

      False

  • 14. 
    If a method needs to be called polymorphically, what type of reference should be used to point to the object that the method is being called with?
    • A. 

      A reference of the base class that defines the behavior of the object

    • B. 

      A reference of the same type as the object

    • C. 

      An object reference to the actual object

    • D. 

      None of the above.

  • 15. 
    Select the best true statement:
    • A. 

      Polymorphism is indicated by a runtime warning from the FCL.

    • B. 

      Polymorphism is indicated by the use of the keyword virtual in a method signature.

    • C. 

      Polymorphism is indicated by the use of the keyword override in a method signature.

    • D. 

      Both B and C are correct statements.

  • 16. 
    Which declaration declares abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)?
    • A. 

      Public int method1();

    • B. 

      Public int abstract method1();

    • C. 

      Public abstract int method1();

    • D. 

      Public int nonfinal method1();

  • 17. 
    Consider the abstract class below: public abstract class Foo { private int a; public int b; public Foo( int aVal, int bVal ) { a = aVal; b = bVal; } // end Foo constructor public abstract int calculate(); } // end class Foo Any concrete subclass that extends class Foo:
    • A. 

      Must implement a method called calculate.

    • B. 

      Will not be able to access the instance variable a.

    • C. 

      Will not be able to instantiate an object of class Foo.

    • D. 

      All of the above.

  • 18. 
    Assigning a derived class reference to a base class variable is safe:
    • A. 

      Because the derived class has an object of its base class.

    • B. 

      Because the derived class is an object of its base class.

    • C. 

      Only when the base class is abstract.

    • D. 

      Only when the base class is concrete.

  • 19. 
    Attempting to instantiate an object of an abstract class is a logic error.
    • A. 

      True

    • B. 

      False

  • 20. 
    The keyword sealed is applied to methods and classes to:
    • A. 

      Prevent overriding and inheritance

    • B. 

      Guarantee an implementation exists

    • C. 

      Specify a class is concrete

    • D. 

      None of the above.

  • 21. 
    Classes and methods are declared sealed for all of the following reasons, except:
    • A. 

      Sealed methods allow inlining the code.

    • B. 

      Sealed methods and classes prevent further inheritance.

    • C. 

      Sealed methods are static.

    • D. 

      Sealed methods can improve performance.

  • 22. 
    Declaring a method sealed means:
    • A. 

      It will prepare the object for garbage collection

    • B. 

      It cannot be accessed from outside its class

    • C. 

      It cannot be overloaded

    • D. 

      It cannot be overridden

  • 23. 
    Sealing methods allows the compiler to optimize the program by "inlining code."
    • A. 

      True

    • B. 

      False

  • 24. 
    A(n) ________ is best used for providing services that bring together objects of otherwise unrelated classes.
    • A. 

      Abstract class

    • B. 

      Concrete class

    • C. 

      Interface

    • D. 

      None of the above.

  • 25. 
    The purpose of an interface is to:
    • A. 

      Provide similar objects with the same functionality, even though each will implement the functionality differently

    • B. 

      Provide different types of objects with the comparable functionality, even though each will implement the functionality differently

    • C. 

      Provide default implementations of methods and properties

    • D. 

      None of the above.

Back to Top Back to top