Chapter 9 COP3300

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

There may be more than one correct answer. You must give all correct answers for full credit. A program decides after it begins to run what function to execute in response to a statement such as refToObject.func()is an example of...

late binding virtual functions polymorphism

There may be more than one correct answer. You must give all correct answers for full credit. Which of the following can be virtual?

ordinary functions destructors

There may be more than one correct answer. You must give all correct answers for full credit. A pure virtual function is a member function

that is used in a base class that is used to force all derived classes to implement that member function or be a pure virtual function member of the derived class whose declaration ends with = 0.

Suppose class D is derived from class B, and class B has a public member function whose declaration is virtual void f();. Suppose class D has its version of the function, void f(). Here is a function definition and an invocation. void g( B& b) { // other code b.f(); // other code } ; g( dObject ); Suppose this is embedded in an otherwise correct and complete program. Which version of f() will be called?

D::f()

Suppose class D is derived from class B, and class B has a public member function whose declaration is virtual void f();. Suppose class D has its version of the function, void f(). Here is a pointer definition and an access to a member function.. B* bPtr = new D; BPtr->f(); Suppose this is embedded in an otherwise correct and complete program. Which version of f() will be called?

D::f()

A class that has a pure virtual member function is called a concrete base class.

False

A pointer to objects of a derived class can be assigned pointers to objects of the base class in the inheritance hierarchy.

False

Destructors are automatically virtual.

False

Downcasting causes the slicing problem.

False

In C++, a virtual destructor is invoked whenever a virtual constructor was used to create the object.

False

In a class, functions declared with the virtual keyword need not be defined.

False

Indicate if the following statements are True or False. This is legal code. class B { public: // . . . virtual void f() = 0; }; int main() { B b1, b2; /*. . .*/ }

False

It is OK to assign between objects of base type and objects of derived type.

False

Redefining and overriding are exactly the same thing.

False

The base class destructor must be virtual.

False

The virtual property is not inherited.

False

Upcasting causes no problems:

False

If the override specifier is added to the end of a member function declaration, what happens if the function is not specified as virtual in the parent class?

There is a compiler error.

A derived class destructor always invokes the base class destructor.

True

Binding of a virtual function is done at runtime if called using an object.

True

It is legal to have all member functions of a class be pure virtual functions.

True

It is useful to define a class for which no objects may be defined.

True

No objects can be defined of abstract base class type since it is an incomplete definition.

True

Only member functions can be virtual.

True

The virtual function mechanism binds the "right" function to objects.

True

Virtual functions allow old code to call new code.

True

Virtual functions are implemented with a table look up that is done at run time.

True

What keyword is added to member function declaration to prevent it from being overridden in a child class?

final

Suppose class D is derived from class B, and class B has a public member function whose declaration is void f();. Suppose class D has its version of the function, void f(). Here is a function definition and an invocation. void g( B& b) { // other code b.f(); // other code } ; g( dObject ); Suppose this is embedded in an otherwise correct and complete program. Which version of f() will be called?

B::f()

Suppose class D is derived from class B, and class B has a public member function whose declaration is void f();. Suppose class D has its version of the function, void f(). Here is a pointer definition and an access to a member function.. B* bPtr = new D; BPtr->f(); Suppose this is embedded in an otherwise correct and complete program. Which version of f() will be called?

B::f()


संबंधित स्टडी सेट्स

Bio 108 Unit 1 Exam (With Images)

View Set

Chem. Semester Exam Review (Term on Front)

View Set

Chapter 4 - The Contract of Sales and Leases

View Set

LD 35 - Firearms and Chemical Agents

View Set

Business Law Exam 1 Review Question Batch Questions ch. 6-10

View Set

Biology Practice Exam 1 (Ch.22-25)

View Set

GOVT 2305: UNIT 1 Smartbook CH 11

View Set

Abnormal Psychology Exam 4 Module 10

View Set