(A) Show Class Declarations in C++ To Support The Following Class Hierarchy.
(A) Show Class Declarations in C++ To Support The Following Class Hierarchy.
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)
(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.
(m)What are the different types of inheritance? Draw their representations and name
them.
(o) How can we call the constructor of the base class in derived class?
(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(){