APTITUDE QUESTION AND ANSWERS

1. What is virtual constructors/destructors?
Virtual destructors: If an object (with a non-virtual
destructor) is destroyed explicitly by applying
the delete operator to a base-class pointer to the
object, the base-class destructor function
(matching the pointer type) is called on the object.
There is a simple solution to this problem – declare a
virtual base-class destructor. This makes all
derived-class destructors virtual even though they
don’t have the same name as the base-class
destructor. Now, if the object in the hierarchy is
destroyed explicitly by applying the delete operator
to a base-class pointer to a derived-class object, the
destructor for the appropriate class is called.
Virtual constructor: Constructors cannot be virtual.
Declaring a constructor as a virtual function is
a syntax error. Does c++ support multilevel and
multiple inheritance?
Yes.
What are the advantages of inheritance?
• It permits code reusability.
• Reusability saves time in program development.
• It encourages the reuse of proven and debugged
high-quality software, thus reducing problem
after a system becomes functional.
What is the difference between declaration and
definition?
The declaration tells the compiler that at some later
point we plan to present the definition of this
declaration.
E.g.: void stars () //function declaration
The definition contains the actual implementation.
E.g.: void stars () // declarator
{
for(int j=10; j>=0; j--) //function body
cout<<”*”;
cout<
}




2. What do you mean by pure virtual functions?
A pure virtual member function is a member function
that the base class forces derived classes to
provide. Normally these member functions have no
implementation. Pure virtual functions are
equated to zero.


class Shape { public: virtual void draw() = 0; };
3. What is namespace?
Namespaces allow us to group a set of global classes,
objects and/or functions under a name. To say
it somehow, they serve to split the global scope in subscopes
known
as namespaces.
The form to use namespaces is:
namespace identifier { namespace-body }
Where identifier is any valid identifier and namespacebody
is the set of classes, objects and
functions that are included within the namespace. For
example:
namespace general { int a, b; } In this case, a and b
are normal variables integrated within the
general namespace. In order to access to these
variables from outside the namespace we have to
use the scope operator ::. For example, to access the
previous variables we would have to put:
general::a general::b
The functionality of namespaces is specially useful in
case that there is a possibility that a global
object or function can have the same name than
another one, causing a
redefinition error.


4. What is RTTI?
Runtime type identification (RTTI) lets you find the
dynamic type of an object when you have only a
pointer or a reference to the base type. RTTI is the
official way in
standard C++ to discover the type of an object and to
convert the type of a pointer or reference
(that is, dynamic typing). The need came from practical
experience with
C++. RTTI replaces many homegrown versions with a
solid, consistent approach.


5. What is a template?
Templates allow to create generic functions that admit
any data type as parameters and return value
without having to overload the function with all the
possible data types. Until certain point they fulfill
the functionality of a macro. Its prototype is any of the
two following ones:
template function_declaration;
template
function_declaration;
The only difference between both prototypes is the use
of keyword class or typename, its use is
indistinct since both expressions have exactly the same
meaning and behave exactly the same way.

Custom Search
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Powerade Coupons