0% found this document useful (0 votes)
45 views3 pages

(A) Show Class Declarations in C++ To Support The Following Class Hierarchy.

The document contains a quiz for an object-oriented programming class with multiple choice and short answer questions about C++ and OOP concepts. The questions cover topics like class hierarchies, inheritance types, virtual functions, dynamic binding, access control, and more. </SUMMARY>

Uploaded by

REBEL USMAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views3 pages

(A) Show Class Declarations in C++ To Support The Following Class Hierarchy.

The document contains a quiz for an object-oriented programming class with multiple choice and short answer questions about C++ and OOP concepts. The questions cover topics like class hierarchies, inheritance types, virtual functions, dynamic binding, access control, and more. </SUMMARY>

Uploaded by

REBEL USMAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Object-Oriented Programming (CS2133) – Quiz 4

Name:________________________ Registration Number:_________________

Q.1 Answer the following:


(a) Show class declarations in C++ to support the following class hierarchy. (7)

B C D

E F

G
(b) What are different types of inheritance? Draw representations and name them. (10)

(c) Can destructors be virtual? What is the purpose of a virtual destructor? (3)

(d) Explain the diamond problem with an example code? (10)


(e) Describe the purpose of pure virtual member function. (3)

(f) Does C++ support dynamic binding? Give an example with simple code. (5)

(g) Is declaring virtual functions enough to enable dynamic binding or there needs something else?
(3)

(h) Do you think that it is good practice to declare pure virtual function in the most derived class? If
not, then what would be the good practice? (2)

(i) If delete operator is applied to a base class pointer then only base class destructor would be
called even if the destructor is virtual in the base class. Do you agree? Justify your answer.
(3)

(j) Suppose Horse and Cat classes have been derived from Mammal class? Which of the following
statements are wrong? Write in front of // (4)
class Mammal{ };
class Horse: public Mammal{ };
class Cat: public Mammal{ };

void main()
{
Mammal *m = new Horse(); //
Horse *h1 = new Horse(); //
Cat *c = new Cat(); //
Horse *h2 = new Mammal(); //
m = h1; //
m = c; //
c = m; //
}
(k) Explain the difference between the private and protected members of a class.

(l) How do we differentiate between association, aggregation, and composition in terms of


ownership and life-cycle.

(m)What are the different types of inheritance? Draw their representations and name
them.

(n) Explain the diamond problem?

(o) How can we call the constructor of the base class in derived class?

(p) Fill the following access control and inheritance table.

Access public protected private


Same class
Derived classes
Outside classes

(q) How it would be possible to display the name of the class of an object in main function which
belongs to the following class?

class MyOwnClass { };

void main(){

You might also like