You are on page 1of 2

Question: What are Virtual Functions?

Ans: Virtual function is a member function declared in the base class whose fun
ctionality is redefined (same function name) by its derived class. To implement
a virtual function simply precede function name with keyword virtual. A virtual
function declared in the base class represents the single interface and its rede
finition by the derived class implements operations specific to each derived cla
ss.
Question: What is a Namespace?
Ans: A namespace is a declarative region that attaches an additional identifier
to any names declared inside it. It overcomes the problem of name conflicts (of
variable, functions, classes or types) that may occour independently developed
functions. It is possible to use the same name in separate namespaces without co
nflict even if the names appear in the same translation unit. It allows to group
entities like classes, objects and functions under a name.
Question: Explain the need for Virtual Destructor .
Ans: Virtual destructor is needed to make destructor as dynamically bounded. Whe
n we destroy object of a derived class with non-virtual destructor explicitly, o
nly destructor of base class is executed and not of the derived class. Reason of
non-execution of the derived class is that the compiler uses static binding whe
n calling the destructor. this problem can be overcome by making the destructor
to be dynamically bounded which is possible by making the base class of destruct
or virtual.
Question: Can we have private constructor in a class?
Ans : Yes. When we want that object of a class can be created only from inside t
he class then we can have private constructor.
Question: What is the use of Operator Overloading?
Ans: Operator overloading is a property of giving additional meaning to existin
g operator so that they can work with variables of user-defined data types also
in addition to specific built-in data types.
Major uses of operator overloading are:
(i) It enhances the capability of existing operators by making them to work o
n user-defined data types in addition to built-in data types.
(ii) It is used in large and complex programs involving multiple objects of di
fferent classes as it provides a common interface to a operator.
Question: What is the main difference between new and malloc()?
Ans :New operator allocates memory and call the constructor of the class whereas
malloc() only allocates memory.
Question: What is the main difference between delete and free()?
Ans: Delete operator calls the destructor and then deallocates memory whereas fr
ee() only deallocates memory and not call the destructor?
Question: What is the difference between an object and a class?
Ans: Object is an entity with identification, with some characteristics and beh
avior whereas class is a group of objects that have common properties and relati
onship. In fact objects are variables of data type class.
Question: What is the difference between class and structure?
Ans: Major differences between a class and a structure are:
(i) Class is collection of objects of similar objects whereas structure is colle
ction of members of different data types.
(ii) By default all the members inside the class are private whereas all declara
tions inside a structure are public by default.
(iii) The structures are value types and the classes are reference types.
(iv) Classes can be inherited whereas structures can not be.
(v) Fields can be directley instanciated but not in classes.
Question: What is a scope resolution operator?
Ans: For the ease of user, some member function(generally lengthy) are declare
d in the class but they are defined outside the class. Now to bind such functio
n with class scope resolution operator ( denoted as :: ) is used . It is an oper
ator that informs compiler that the given function is a member of a class even t
hough function has been defined outside the class.
Question: What is name mangling?
Ans: Name mangling is a technique used by compiler for calling overloaded functi
on by changing their names.
Question: What is function overloading and operator overloading?
Ans: Function overloading is a property by which a family of functions performi
ng similar multiple related activity share a common name (but different argument
s) . When a overloaded function is called, it is the responsibility of the compi
ler to select the appropriate function depending upon the number of arguments.
Operator overloading is a property of giving additional meaning to an existing o
perator so that it is defined for some user-defined data-types in addition to it
s earlier defined data types. It does not change the original meaning of the ope
rator, rather it extends the existing functionality of the operator.

You might also like