Page 1
CS2203 - Object Oriented Programming
Branch: B.E Computer Science and Engineering
Year: II Semester: III
Prepared By,
L. Maria Michael Visuwasam
Assistant Professor, CSE
1. Define Constructor.
A constructor is a special member function whose task is to initialize the objects of its
class. The constructor name is same as class name. It is called constructor because it
constructs the values of data members of the class.
2. List some of the special characteristics of constructor
They should be declared in the public section.
3. Give the various types of constructors. There are four types
constructor that accepts no parameters
It can take arguments
One argument constructor it can take one argument
Two argument constructor it can take two arguments
Multiple argument Constructor it can more than 2 arguments.
It takes a reference to an object of the same class as itself as an
- used to allocate memory while creating objects.
4. What are the ways in which a constructor can be called?
The constructor can be called in two ways, they are.
L. Maria Michael Visuwasam
Page 1

Page 2
integer int1(0,100);
Class objects can be initialized dynamically. The initial values of an object may be
ime. The advantage of dynamic initialization is that we can
provide various initialization formats, using overloaded constructors. It provides
at have been created by a constructor. It
by a
What is an operator function. Describe the syntax of an operator function.
> operator
L. Maria Michael Visuwasam
Eg: integer int1=integer(0,100);
State the dynamic initialization objects.
provided during run t
flexibility of using different data formats.
Define Destructor.
A destructor is used to destroy the objects th
is a special member function whose name is same as the class and
tilde „~‟ symbol.
The general form is
Return-type classname :: operator op(arug list)
{ Function body }
Where return type -> type of value returned Operator -> keyword Op
being overloaded.
8. List the rules for operator overloading.
follow the syntax rules of the original operators.
9. List some of operators that cannot overload in C++.
10. What are the conditions to be satisfied for casting?
11. What are the types of type conversion?
ersion from basic type to class type

Page 3
12. What is operator overloading?
The mechanism of giving such special meanings to an operator is known as operator
overloading. or In c++ you can give special meanings to operators when they are used with
user defined classes. This is called operator overloading.
13. Why is it necessary to overload an operator?
To define a new relation task to an operator, we must specify what it means in relation to the
class to which the operator is applied. This is done with the help of a special function called
operator function. Or It allows the developer to program using notation closer to the Unit-2_2 marks questions with answers
domain and allow user types to look like types built into the language. Or The ability to tell
the compiler how to perform a certain operation when its corresponding operator is used on
one or more variables.
14. What is a conversion function? How it is created? Explain its syntax
The type of data to the right of an assignment operator is automatically converted to the type
of the variable on the left. For e.g., the statements int m; float x=3.14; m=x; Convert x to an
integer before its value is assigned t0 m. thus the fractional part is truncated.
15. When is a friend function compulsory? Give an eg.
A friend function is necessary when you define a function outside the class. And to access the
private members of the class or the member function and also friend class can directly access
the private and protected data.
16. What is meant by copy constructor?
A copy constructor takes a reference to an object of the same class as itself as an argument.
17. What is the need of object initialization?
specific default values.
18. What are the two main functions of constructors?
The two main functions are
1. It automatically initializes the object
2. It usually provides initial values for the data members of the object.
19. What are the rules for defining constructor?
st have the same name as the class itself.
different names and same arguments.
uctor should not have a return statement in the body of the constructor itself.
20. What are the operators which cannot be overloaded as a friend?
1. Assignment operator =
L. Maria Michael Visuwasam
Page 3

Page 4
2. Function call operator ()
3. Array Subscript operator []
4. Access to class member using pointer to object operator ->
21. What are the restrictions of operator overloading
-defined types. All overloaded must have at least
one argument as user defined type.
22. Difference between overloading of unary and binary operator
All operators having a single argument are unary operators. When we overload these
operators as member functions, we do not need to pass any argument explicitly. The pointer
pointing to invoke object is passed as an implicit argument. Operators with two operand are
known as binary operators. They will have a single argument when defined as member.
23. What are function objects.
Objects of the classes where () operator is overloaded. In the case objects can be written with
a () and can be treated like functions. Such objects which can be called like a function are
known as function objects.
24. What are the different types of conversion? Compare them
A constructor converts from a foreign object to a native object while an operator converts a
native object to a foreign object.
25. What is wrapper class. A Class which makes a C-like struct or abuilt-in type data
represented as a class. For e.g. an integer wrapper class represents a data type int as a class.
26. Difference between constructor and destructor.
It is used to construct the object.
It is used to destroy the object.
It can be called automatically when an object It is called when an object goes out of scope.
comes into existence.
The constructor function is called every time The destructor function is called every time
an object is created.
the program exits a block.
L. Maria Michael Visuwasam
Page 4

Page 5
It is the function invoked first before calling It is function called at last.
any function.
It takes any number of arguments.
It takes no argument.
It can be overloaded.
It cannot be overloaded.
Constructor name and class name should be Destructor name and class name should be
the same.
the same but it is prefixed by ~
Eg: student()
Eg: ~student()
It cannot be declared as virtual function.
It can be a virtual function.
It behaves like a new operator
It behaves like a delete operator.
27. Comparison between conversion constructor and conversion operator function.
Conversion constructor:
It is used to convert from some other object to native object. In other words, it
converts foreign object to native object.
If conversion is needed from firs class to second class then constructor is required.
Conversion operator function:
It is used to convert from native object to other object. In other words, it converts
from native object to foreign object.
It conversion is needed from second class to first class then conversion operator
function is required.
L. Maria Michael Visuwasam
Page 5