C Imp Questions
C Imp Questions
Overloading - same method name with different arguments, may or may not be same return type
written in the same class itself.
Example:
class CClass
{
string print( int i);
string print(int i, char c);
};
4.Explain the need for "Virtual Destructor"
When classes are inherited we need to make the base class destructor virtual to make sure when
the object is destroyed all the derived class destructors also called. Otherwise the derived class
destructors are not called because the there is compile time binding of the destructor pointer to
the base class destructor.
5.Can we have "Virtual Constructors"?
In C++, Virtual is Used foe polymorphism, which is calling a Derived class function using the Base
class pointer. Since all the functions in the Public, protected are inherited we may have virtual
functions. BUT BUT Constructor of a class is never and ever extended by a derived, hence we
will never heed to have a Virtual constructor
6. What are the different types of polymorphism?
It is reacting differently for the same kind of message. For example, Consider Parrot,Penguin &
tiger .My message is "approach me quickly". Their different reactions: Parrot approaches me by "
flying" Penguin approaches me by "swimming" Tiger approaches me by "running" Here my
message is simply "pproach me quickly" But different things have been reacted differently. This is
called Polymorphism. As far as my knowledge is concerned there is only one type of
polymorphism and that is runtime polymorphism.