| Back to Questions Page |
| |
| Question |
In c++ there is only virtual destructors, no constructors. Why? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | constructors are invoked at the time of object creation.
The v-table for virtual function mechanism is not
intialised properly during the constructor invocation.
So constructors cannot be virtual
But,destructors can be virtual.Because the V-table is
properly initialised at the time of object creation.
So the v-table is available for the destructors.
Destructors can be made pure virtual also.But unlike other
member functions,it must be redfined outside the class.  |
| Uma Sankar Pradhan |
| |
| |
| Answer | Since OOPS basics says always base class object to be
created and than its derivatives. So just consider the case
where we try to create object of derived class with virtual
contructor since pointer points to derived type object it
fetches derived constructor directly, without its base
class object constructed( instantiated )...
So Constructor cannot be made virtual bt when comes to case
of Destructor object destuction process must be reverse...
So we must make destructor as virtual.
This applies only when we going for Dynamic Memory
Allocation...
If, on the other hand, you were to have a pointer to object
A and assign it a dynamic object B, when you destroy it,
only object A's destructor is called and object B part of
the object is never destroyed. Virtual destructors are used
to solve this problem and destroy the objects in the right
order.  |
| Bala Preethi |
| |
| |
| Question |
What is virtual constructors/destructors? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | virtual constructors are used when we need to avoid the
copy same. desructor frees the memory with a ~(tilde) symbol
 |
| Khadeer.k |
| |
| |
|
|
| |
| Answer | there is no virtual constructor..coz..virtual thing is in
run time n constructor ic compile time thing.  |
| Debasish |
| |
| |
| Answer | There is nothing like virtual constructors but we can have
virtual destructors so that the destructor of the correct
object is called.
Ex.
Base *bptr = new derived()
delete bptr; then the destructor of the derived objetc is
called when the base destructor is marked as virtual.
else destructore of base class is called and may lead to
memory leak if we have allocated any new memory.  |
| Nk |
| |
| |
| Question |
What is the difference between declaration and definition? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Declaration means we are just creating a variable or method.
Defination means we are assigning some value for a variable
& doing some functions in method  |
| S |
| |
| |
| Answer | During declaration we just specify the type and no memory
is allocated to the variable. But during the definition an
initial value is assigned and memory is allocated to the
variable.  |
| Roshan |
| |
| |
| Answer | Declaration means only declaring a function or a variable
with its return type or datatype respectively.
Definition means assiging values to variable or procedure
to be performed by a function.  |
| Sandhya Shetty |
| |
| |
| Answer | Declaration means,we just inform to compiler return
type,funtion name and argument list of funtion that later
use in program.Definition define the operation of that
funtion.  |
| Deepanjali Joshi |
| |
| |
| Answer | The definition is the one that actually allocates space,
and provides an initialization value, if any.
There can be many declarations, but there must be exactly
one definition. A definition tells the compiler to set
aside storage for the variable. A declaration makes the
variable known to parts of the program that may wish to use
it. A variable might be defined and declared in the same
statement  |
| Sanjay |
| |
| |
| Answer | Declaration means just telling to complier about variable
or function but definition means actually allocating memory
for variable.  |
| Omkar |
| |
| |
| Question |
When is a memory allocated to a class? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | When instance of that class is creater by us  |
| Teginder |
| |
| |
| Answer | A class is a template.As Teginder said,it will get
allocated memory when u create object of that class.  |
| Ramakrishna |
| |
| |
| Answer | when an object of that class is created and constructor
runs. memory is allocated in Stack (part of RAM)  |
| Achal |
| |
| |
| Question |
What are the advantages of inheritance? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | In OOPs, the concept of inheritance provides the idea of
reusability. This means that we can add additional features
to an existing class without modifying it.
This is possible by deriving a new class from the existing
one. The new class will have combined features of both the
classes.  |
| Sidhi.r |
| |
| |
| Answer | using inheritance we can increase the reusability.As we can
use that functions whish we have maid earlier  |
| Miss.purvi Mota |
| |
| |
| Question |
Does c++ support multilevel and multiple inheritance? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
| This Interview Question Asked @ Wipro |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | yes.  |
| Nisha |
| |
| |
| Answer | Yes ,c++ supports multilevel and multiple inheritance  |
| Devarathnam |
| |
| |
| Answer | yes  |
| Ramu |
| |
| |
| Answer | Yes, Cpp upports multilevel and multiple inheritance.
regards,
Praneet sahay  |
| Praneet Sahay |
| |
| |
| Answer | yes c++ supports these inheritance's  |
| Bhagavathi Chouhan |
| |
| |
| Question |
What do you mean by pure virtual functions? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | pure virtual function is one which has no definition but
only declaration. This is defined in base class. The
instance of such base class can not be created  |
| Guest |
| |
| |
| Answer | A pure virtual function is a function that must be
overridden in a derived class and need not be defined. A
virtual function is declared to be "pure" using the
curious "=0"
syntax:
class Base {
public:
void f1(); // not virtual
virtual void f2(); // virtual, not pure
virtual void f3() = 0; // pure virtual
};  |
| Manjusinga |
| |
| |
| Answer | Any class containing any pure virtual function cannot be
used to create object of its own type.
And any class which is derived by such class must either
define the function or redefine the function.  |
| Nk |
| |
| |
| Answer | May the pure virtual function be called by the function
declared and implemented in the base class?  |
| Mx |
| |
| |
| Question |
Why do we use virtual functions? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | The virtual function can be allowed in base classes only.
The functions markd Virtual will only be overridable in
derieved classes.
If i m having a function in base class that shud come in
derieved class but i want it to have different behaviour.
This can only be acheived only if base class function is
virtual function.  |
| Bijal |
| |
| |
| Answer | we use virtual functions to achive dynamic binding
Dynamic binding is establishing relation between the
function call and function definition at run time  |
| Uma Sankar Pradhan |
| |
| |
| Answer | 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; };  |
| Td |
| |
| |
| Question |
What is the difference between pass by reference and pass by
value? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
| This Interview Question Asked @ TCS |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | in pass by referance the parameters are passed as the
address of the variables whereas in pass by value the
variables are directly passed as parameters  |
| Anandan |
| |
| |
| Answer | In case of pass by value..the change in the sub-function
will not cause any change in the main function wheareas in
pass by reference..the change in the sub-function will
change the value in the main function..  |
| Subha Raman |
| |
| |
| Answer | passing an object by value is defined by the copy
constructor of that object's class. This can make pass-by-
value an extremely expensive operation.  |
| P Suresh Kumar |
| |
| |
| Answer | in pass by referce function can access original memory
location of variable so can access value while in case of
pass by value fuction can copy the value of variable to the
prototype of its kind of variable so calling funcion can
access the prototype variable but not the direct original
variable.  |
| Ganesh |
| |
| |
| Answer | in Pass by value; if any change in variable in the sub-
function may not reflected to the main function. where as
in pass by reference the change in the variable may reflect
to the original value in the main funtion.
ex : // Pass by Reference
void Get( int &nIndex){
nIndex = 10;
}
void main()
{
int x = 100;
cout<<Get( x );
}
o/p : 10;
ex : // Pass by Value
void Get( int nIndex){
nIndex = 10;
}
void main()
{
int x = 999;
cout<<Get( x );
}
o/p : 999  |
| Chinna |
| |
| |
| Answer | Pass By Value:
1.It passes the actual value of parameter from the function
call.
2.Value of the parameter variable in calling functions
remains unchanged.
3.copy of the variable of actual parameter are made and
transfer to the formal parameter.
call By Reference:
1.the address of the actual parameter has to be transfered
2.the formal parameter in the function decleretion must of
pointer type.
3.Any changes in the formal parameter can change the value
of actual patameter.  |
| Manila |
| |
| |
| Question |
What is namespace? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | A namespace is an abstract container or environment created
to hold a logical grouping of unique identifiers (i.e.,
names).
Namespaces allow to group entities like classes, objects
and functions under a name.  |
| Kiruthika |
| |
| |
| Answer | namespace is a one of the problems solved by namespaces,
that of conflicting class names  |
| Kumarasamy |
| |
| |
| Answer | it is used to solve the problem when there is conflict
between class names  |
| Naveen Kumar |
| |
| |
| Answer | namespace is used to avoid class name collision.  |
| Vadivel |
| |
| |
| Answer | Namespace is logical group of classes.It can span multiple
assembly.  |
| Ritesh Kumar Rawat |
| |
| |
| Answer | Namespace is a group of classes, structures, interfaces,
enumerations, and delegates, organized in a logical
hierarchy by function, that enable you to access the core
functionality you need in your applications.
Namespaces are the way that .NET avoids name clashes
between classes. A namespace is no more than a grouping of
data types, but it has the effect that the names of all
data types within a namespace automatically get prefixed
with the name of the namespace. It is also possible to nest
namespaces within each other.  |
| Ritesh Kumar Rawat |
| |
| |
| Question |
What are generic functions and generic classes? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Generic functions are functions which are not used for any
particular datatype..they are useful for anydatatype Ex: if
you write code for the Sorting program using templates then
the function is useful for any data type to sort...Generic
classes are same as generic functions  |
| Draku |
| |
| |
| Answer | Generic functions are the function which return void ptr...
(void*)...
Generic Classes are template classes...
Basicaly we implement both of them for reusability.. and
abstraction..  |
| Nikhil Kapoor.. |
| |
| |
| Question |
What is R T T I ? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
| This Interview Question Asked @ Ness-Technologies |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | Run time type identification.
through typeid operator we can justify object at run time.  |
| Sanjay Makwana, Puna |
| |
| |
| Answer | RTTI> Run Time Type Identification
RTTI means during time of run object property can be
retrieve and changed. Under RTTI dynamic_cast<>, typeid,
const_cast<> etc are used.  |
| Arun |
| |
| |
| Answer | Run Time Type Information ( RTTI ) : Run-time type
information (RTTI) is a mechanism that allows the type of
an object to be determined during program execution.
There are three main C++ language elements to run-
time type information:
The dynamic_cast operator : Used for conversion of
polymorphic types.
The typeid operator : Used for identifying
the exact type of an object.
The type_info class : Used to hold the type information
returned by the typeid operator.  |
| Chinna |
| |
| |
| Question |
What are the main differences between procedure oriented
languages and object oriented languages? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | procedure oriented language doesnot support oops.
object oriented languages support opps concept.  |
| Shivanand |
| |
| |
| Answer | 1. Procedural languages enforce sequential processing
of instructions. Object oriented languages may implement
event driven processing.
2. Procedural languages store all data as global while
OOPs languages support data encapsulation -- all related
data is stored inside one object and only relevant data is
shown to the user.
3. Facilities like function overloading and operator
overloading (polymorphism) allow you to use same names and
provide different functionality which avoids personalism in
naming conventions. These overloaded versions are easy to
use and remember.  |
| K.rajesh |
| |
| |
| Answer | procedural language: instructions will be divided into
various blocks called as datas .It concentrates on
procedures rather than datas.
oops: class is created where data and functions are
encapsulated. It concentrates on data rather than
procedure.  |
| Rahul Madanan |
| |
| |
| Answer | Procedure Oriented Language: It follows the a procedure
that is simply saying it will go line by line in the code
unless if u mentioned any goto are any code breaking
keywords.
Object Oriented Language: In this each and every program is
called as Object. that is simply saying we will breake the
code in to small pieces and we will call the code when we
want.  |
| Varaprasad |
| |
| |
| Question |
What is a template? |
Rank |
Answer Posted By |
|
Question Submitted By :: Tribhuvan Sharma |
|
I also faced this Question!! |
© ALL Interview .com |
| Answer | The template specifies a set of parameterized classes or
functions.  |
| P Suresh Kumar |
| |
| |
| Answer | Templates is one of the features added to c++ recently.a
template can be considered as a kind of macro.  |
| Debika Mohapatra |
| |
| |
| Answer | Templates is one of the features added to c++ recently.a
template can be considered as a kind of macro.
Templates are mainely used for creating the generic classes  |
| Yughandhar |
| |
| |
| Answer | Template is used for generic programming. In other words
when you want to write a function or a class type
independent, go for templates.
template<class T>
void fun(T x, T y); // Is a Template function
template<typename T>
class abc{
T m;
}; // Is a Class Template
template<class T>
class abc{
T m;
}; // Is a Class Template  |
| Ravinandan |
| |
| |
| Answer | templates r used to create generic classes and functions.  |
| Yughandhar |
| |
| |
|
| |
|
Back to Questions Page |