Filters
Question type

Study Flashcards

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

A) True
B) False

Correct Answer

verifed

verified

A derived class destructor always invokes the base class destructor.

A) True
B) False

Correct Answer

verifed

verified

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

A) True
B) False

Correct Answer

verifed

verified

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

A) True
B) False

Correct Answer

verifed

verified

Write a program where the destructors should be virtual.Explain.

Correct Answer

verifed

verified

The requested code and further discussion follow. #include<iostream> using namespace std; class B { public: B():bPtr( new int[5]){ cout << "allocates 5 ints\n";} virtual ~B() { delete[] bPtr;cout << "deallocates 5 ints\n";} private: int * bPtr; }; class D:public B { public: D():B(),dPtr(new int[1000]){cout << "allocates 1000 ints\n";} ~D(){ delete[] dPtr;cout << "deallocates 1000 ints\n";} private: int * dPtr; }; int main() { for (int i = 0;i < 100;i++) { B* bPtr = new D; delete bPtr; } cout << "\nWithout virtual destructor,\n"; cout << "100 * 1000 + 500 ints allocated\n" << "but only 500 ints deallocated.\n"; cout << "\nWith virtual destructor,\n"; cout << "100 * 1000 + 500 ints allocated,and " << "100 * 1000 + 500 ints deallocated.\n"; } In this code,if the base class destructor is not virtual,the system must bind the pointer to the destructor at compile time.The pointer in main,bPtr,is of type B*,i.e. ,pointer to B,so it is bound to B's member functions.The destructor for D,~D fails to run. If the keyword virtual is removed from the destructor in the base class,class B,the derived class destructor ~D is not called.Approximately 400K of memory would then be leaked.

A the binding of virtual function is done at runtime if called using an object.

A) True
B) False

Correct Answer

verifed

verified

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

A) True
B) False

Correct Answer

verifed

verified

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

A) True
B) False

Correct Answer

verifed

verified

True

Write a class having a public pure virtual method.You need not put any other members in the class.

Correct Answer

verifed

verified

class Figu...

View Answer

Which functions in class D are virtual? class B { public: virtual void f(); virtual void g(); // ... private: //... }; class D : public B { public: void f(); void g(int); private: // ... };

Correct Answer

verifed

verified

The function void f(...

View Answer

Redefining and overriding are exactly the same thing.

A) True
B) False

Correct Answer

verifed

verified

Only member functions can be virtual.

A) True
B) False

Correct Answer

verifed

verified

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

A) True
B) False

Correct Answer

verifed

verified

Upcasting causes no problems

A) True
B) False

Correct Answer

verifed

verified

Late binding refers to a failure to secure one's ski boots.

A) True
B) False

Correct Answer

verifed

verified

It is desirable to develop your programs incrementally.Code a little,test a little.If you do this with virtual functions,you get into trouble.Discuss the problem and the (very simple)solution.

Correct Answer

verifed

verified

If you fail to define functions that has...

View Answer

Write a short program that shows how to defeat the slicing problem.

Correct Answer

verifed

verified

// to defeat the slicing problem
#includ...

View Answer

Suppose each of the base class and the derived class has a member function with the same signature.Suppose you have a base class pointer to a derived class object and call the common function member through the pointer.Discuss what determines which function is actually called,whether the one from the base class or the one from the derived class.Consider both the situations where the base class function is declared virtual and where it is not.

Correct Answer

verifed

verified

The non-virtual case: If the base class ...

View Answer

The virtual property is not inherited.

A) True
B) False

Correct Answer

verifed

verified

Downcasting causes the slicing problem.

A) True
B) False

Correct Answer

verifed

verified

False

Showing 1 - 20 of 34

Related Exams

Show Answer