CUET CS Chapter-Constructors and Destructors 

  • Board
    CBSE
  • Textbook
    NCERT
  • Class
    Class 12
  • Subject
    Computer Science
  • Chapter
    CUET CS Chapter-Constructors and Destructors 
  • Chapter Name
    Constructors and Destructors
  • Category
    CUET (Common University Entrance Test) UG

MCQ-Based Questions for CUET Computer Science Chapter-Constructors and Destructors 

This page is prepared by HT experts and consists of MCQ-Based Questions for the CUET Computer Science chapter-Constructors and Destructors with a detailed explanation of all the questions asked from Constructors and Destructors. To find the solution to the MCQ questions click on the answer tab. Check out chapter-wise CUET computer science Practice MCQ Based Questions. 

Practice Questions for CUET Computer Science chapter-Constructors and Destructors SET-1

Computer Science - MCQ on Constructors and Destructors

Class XII

Q.1 If a class contains a three-argument constructor, then it is necessary to define explicitly a zero-argument, a one-argument and a two-argument constructors. This statement is true when

a) if the class designer wants to allow the creation of objects using zero-argument, one-argument and two-argument constructors.

b) if the class designer does not want to allow creation of objects using zero- argument, one-argument and two-argument constructors.

c) if the class designer wants to allow allocation of memory using zero- argument, one-argument and two-argument constructors.

d) if the class designer does not want to allow creation of objects using zero- argument, one-argument and two-argument constructors.

Answer:

(a)

Explanation: If the class designer wants to allow creation of objects using zero-argument, one-argument and two-argument constructors, then the statement is true, otherwise false.

Q.2 Member functions of the class have to be called

a) explicitly.

b) automatically.

c) implicitly.

d) locally.

Answer:

(a)

Explanation: Member functions are used to modify, retrieve or print the data whenever required and hence are not called automatically.

Q.3 The constructor gets called

a) explicitly.

b) automatically.

c) implicitly.

d) locally.

Answer:

(b)

Explanation: The object creation is a two-step process. Firstly, the memory is allocated and secondly, its data members are initialized. For initialization, constructors are provided which always get called automatically.

Q.4 When only the member functions of the class should be able to create the object of a class, then the constructor should be made

a) global.

b) local.

c) public.

d) private.

Answer:

(d)

Explanation: When we want that a user of the class should not be able to create an object of a class but the member functions of the class should be able to create it then the constructors should be made private.

Q.5 The difference between constructors and the other member function is

a) constructors cannot be overloaded.

b) constructors have a return type.

c) constructors do not return any value.

d) constructors are called explicitly.

Answer:

(c)

Explanation: Constructors are like other member functions of the class and hence can be overloaded. The only difference is that the constructors do not return any value.

Q.6 Static memory allocation takes place during

a) execution.

b) compilation.

c) linking.

d) initialization.

Answer:

(b)

Explanation: Static memory allocation takes place during compilation, whereas, dynamic memory allocation takes place during execution. For example: int i ;

Q.7 Dynamic memory allocation takes place during

a) execution.

b) compilation.

c) linking.

d) initialization.

Answer:

(a)

Explanation: Static memory allocation takes place during compilation, whereas, dynamic memory allocation takes place during execution.

For example: int *i = new int;

Q.8 For the following class, the name of the constructors and destructors is

class weight

{

int x, y;

public:

………..

};

a) ~weight( ) and weight( ).

b) weight( ) and ~weight( ).

c) #weight( ) and weight( ).

d) weight( ) and #weight( ).

Answer:

(b)

Explanation: class weight

{

int x, y;

public:

weight( ) { }

~weight( ) { }

};

Q.9 The properties of destructors are

a) it has an argument but no return value.

b) it has no argument but a return value.

c) it has neither an argument nor a return value.

d) it has both argument and return value.

Answer:

(c)

Explanation: The destructor function has the same name as the class, but with a prefix ~. The destructor has neither an argument nor a return type.

Q.10 For the following program, the object that will invoke constructor1 will be

class Pilot

{

int num;

public:

Pilot(int y){num = y;} //constructor 1

Pilot(Pilot &t); //Constructor 2

};

a) class pt(a)

b) class pt(10

c) Pilot pt(10

d) num pt(a)

Answer:

(c)

Explanation: Pilot is the name of the class. pt is the name of the object and the integer value passed inside it is 10.

Q.11 In the following program, the type of constructor1 is

class Teacher

{

private:

int a;

public:

Teacher( ) //constructor1

{ a =0; }

};

a) parameterized constructor.

b) copy constructor.

c) default constructor.

d) mutual constructors.

Answer:

(c)

Explanation: A constructors that accepts no parameter is called the default constructors. Here, Teacher() is a default constructor, as it accepts no parameters.

Q.12 In the following program, the type of constructor1 is

class ABC{ int i;

public:

float j;

char k;

ABC( int a, float b, char c) //constructor1

{ i = a; j = b; k = c; }

};

a) parameterized constructor.

b) copy constructor.

c) default constructor.

d) mutual constructors.

Answer:

(a)

Explanation: Constructors that take arguments are known as parameterized constructors. Here, the constructor ABC() is taking three arguments.

Q.13 The constructor of the form classname(classname &) is a

a) parameterized constructor.

b) copy constructor.

c) default constructor.

d) mutual constructor.

Answer:

(b)

Explanation: A copy constructor is a special constructor in the C++ programming language used to create a new object as a copy of an existing object. This constructor takes a single argument: a reference to the object to be copied.

Q.14 A copy constructor is called when

a) an object is passed by reference.

b) a function returns no argument.

c) an object is passed by value.

d) no object is passed.

Answer:

(c)

Explanation: The copy constructor is invoked when an object is passed by value to a function. The pass-by-value method requires a copy of the passed argument to be created for the function to operate upon.

Q.15 In copy constructor, an argument is passed by

a) value

b) address.

c) value-result.

d) reference.

Answer:

(d)

Explanation: If the argument is passed by value instead of reference, the compiler runs out of memory.

Q.16 The order of invocation of constructors for the following programs is

class Universe

{

};

class Earth

{

};

class India

{

int plane();

Universe uni;

Earth ear;

};

main()

{

Earth E1;

Universe U1;

India I1;

….

….

}

a) Earth, Universe, Universe, Earth, India.

b) Earth, India, Universe, Universe, Earth.

c) Earth, Universe, India, Universe, Earth.

d) Earth, Universe, Universe, India, Earth.

Answer:

(a)

Explanation: First main() is considered. Inside main(),Earth is called then Universe, then Universe under class India is called, then Earth and finally India.

Q.17 The error in the following code is

class file{

char a,b,c;

public:

char file();

};

a) constructor should not be defined publicly.

b) constructor should have arguments.

c) constructor should not have any return type.

d) constructor should be hidden.

Answer:

(c)

Explanation: char file(); is not correct. As constructor does not have any return type, so char should be deleted.

Q.18 The syntax error in the following program is

class ABC

{

int x = 10;

float y;

ABC( ) {y = 5;}

~ABC() {}

};

void main( )

{

ABC a1,a2;

}

a) line 3 and line 10.

b) line 4 and line 5.

c) line 3 and line 5.

d) line 4 and line 10.

Answer:

(a)

Explanation: In line 3, the class member cannot be initialized here. In line 10, a1 is assigned a value that is never used.

Q.19 The object that will invoke costructor1 in the following code is

class exam

{

int month;

public:

exam(int y){ month = y}; //Constructor 1

exam(exam &t); //Constructor 2

};

a) exam In;

b) exam In();

c) exam (10;

d) exam In(10;

Answer:

(d)

Explanation: exam is the name of the class and In is the name of the object. Inside the brackets, integer value is passed.

Q.20 In the following C++ code, function 1 is referred to as

class Hall

{

public:

Hall( ) //function 1

{ cout << “Leaving the hall” <<endl;}

~TestMeOut( ) //function 2

{ cout << “Entering the hall” <<endl;}

};

a) constructor.

b) private member.

c) destructor.

d) public member.

Answer:

(a)

Explanation: Function1 is constructor and a constructor in a class is a special block of statements called when an object is created.

Computer Science - MCQ on Constructors and Destructors

Practice Questions for CUET Computer Science chapter-Constructors and Destructors SET-2

Q.1 A member function with the same name as its class and that initializes class objects with legal initial class objects is called

a) destructor.

b) destroyer.

c) constructor.

d) temporary object.

Answer:

(c)

Explanation: In object-oriented programming, a constructor in a class is a special block of statements called, when an object is created, either when it is declared or dynamically constructed on the heap through the keyword “new”.

Q.2 An anonymous shortlived object is known as

a) constructor object.

b) temporary object.

c) permanent object.

d) public object.

Answer:

(b)

Explanation: Temporary objects are unnamed objects created on the stack by the compiler. They are used during reference initialization and during evaluation of expressions including standard type conversions, argument passing, function returns, and evaluation of the throw expression.

Q.3 A constructor that takes no arguments is known as

a) copy constructor.

b) virtual constructor.

c) default constructor.

d) destructor.

Answer:

(c)

Explanation: A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values.

Q.4 A constructor that initializes an object with the data values of another values is known as

a) virtual constructor.

b) copy constructor.

c) default constructor.

d) same constructor.

Answer:

(b)

Explanation: A copy constructor is a special constructor in the C++ programming language used to create a new object as a copy of an existing object. This constructor takes a single argument: a reference to the object to be copied.

Q.5 A member function that deinitializes the object before it goes out of scope is known as

a) destroyer.

b) destructor.

c) deinitializer.

d) constructor.

Answer:

(b)

Explanation: Destructors are usually used to deallocate memory and do other cleanup for a class object and its class members when the object is destroyed. A destructor is called for a class object when that object passes out of scope or is explicitly deleted.

Q.6 A constructor with default arguments is equivalent to

a) constructor.

b) destructor.

c) default constructor.

d) implicit constructor.

Answer:

(c)

Explanation: A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values.

Q.7 A destructor is preceded by the symbol

a) ~

b) !

c) ^

d) $

Answer:

(a)

Explanation: A destructor is a member function with the same name as that of its class and is preceded by a tilde(~).

Q.8 The one which is the property of destructors is

a) it can return any value.

b) argument can be provided to it.

c) it cannot be inherited.

d) it is possible to take the address of a destructor.

Answer:

(c)

Explanation: A default constructor is a constructor that either has no parameters, or if it has parameters, all the parameters have default values. Destructors cannot be inherited, though a derived class can call the base class constructor.

Q.9 Private and protected constructors are available only for

a) member functions only.

b) friend functions only.

c) member and friend function.

d) public function.

Answer:

(c)

Explanation: Constructor functions obey the usual access rules. That is, private and protected constructors are available only for member and friend functions, however public constructors are available for all the functions.

Q.10 The feature that is more beneficial than default arguments is

a) overloading.

b) encapsulation.

c) data hiding.

d) abstraction.

Answer:

(a)

Explanation: Default arguments might not work for all possible combinations of arguments whereas a function may be overloaded for all possible combination of the arguments.

Q.11 The initialization in which the initial values is provided during runtime is

a) static initialization.

b) dynamic initialization.

c) public initialization.

d) private initialization.

Answer:

(b)

Explanation: In dynamic initialization, at the time of execution, the values are assigned to the variables.

Q.12 The constructor which can take values as arguments is known as

a) copy constructor.

b) parameterized constructor.

c) default constructor.

d) destructor.

Answer:

(b)

Explanation: In an object-oriented programming, a constructor in a class is a special block of statements called when an object is created, either when it is declared or dynamically constructed on the heap through the keyword “new”. Parameterized constructors take values as arguments into the constructor function when objects are created.

Q.13 In the following C++ code, function 1 is referred to as

class TestMeOut

{

public:

~TestMeOut( ) //function 1

{ cout << “Leaving the examination hall” << endl;}

TestMeOut( ) //function 2

{ cout << “Appearing for examination” << endl;}

voidMyWork( ) //function 3

{cout << “Attempting Questions” << endl;}

};

a) constructor.

b) private member.

c) destructor.

d) public member.

Answer:

(c)

Explanation: Function1 is destructor and it is invoked as soon as the scope of object gets over.

Q.14 The object which will invoke costructor1 in the following code is

class Interview

{

int month;

public:

Interview(int y){ month = y}; //Constructor 1

Interview(Interview &t); //Constructor 2

};

a) Interview In;

b) Interview In();

c) Interview (10;

d) Interview In(10;

Answer:

(d)

Explanation: Interview is the name of the class and In is the name of the object. Inside the brackets, integer value is passed.

Q.15 The order of invocation of constructors for the following programs is

class distance

{

};

class Time

{

};

class figure

{

int plane();

distance dist;

Time stime;

};

main()

{

Time T1;

distance D1;

figure F1;

….

….

}

a) Time, distance, distance, Time, figure.

b) Distance, distance, Time, Time, figure.

c) Time, distance, Time, distance, figure.

d) Figure, distance, Time, distance, Time.

Answer:

(a)

Explanation: First main() is considered. Inside main(), Time is called then distance, then distance under class figure is called, then Time and finally figure.

Q.16 Copy constructor is called when

a) when the object is not initialized with other object of the same type.

b) when a function returns an object.

c) when an object is passed without value to a function.

d) when the object is initialized with object of different type.

Answer:

(b)

Explanation: When a function returns an object, the copy constructor creates a temporary object to hold the return value of the function returning an object.

Q.17 The error in the following code is

class sample{

double a,b,c;

public:

double sample();

};

a) constructor should not be defined publicly.

b) constructor should have arguments.

c) constructor should not have any return type.

d) constructor should be hidden.

Answer:

(c)

Explanation: double sample(); is not correct. As constructor does not have any return type, so double should be deleted.

Q.18 The name of constructor and destructor of the following code is

class weight

{

int x,y;

public:

………

};

a) weight() and ~weight().

b) x() and ~x().

c) y() and ~y().

d) x() and ~y().

Answer:

(a)

Explanation: Constructor and destructor have the same name as that of a class. Destructor is preceded by tilde(~).

Q.19 The number of methods in which the parameterized constructors can pass the value is

a) one.

b) two.

c) three.

d) infinite.

Answer:

(b)

Explanation: Parameterized constructors can pass the values in two ways: by implicit call and by explicit call.

Q.20 A constructor overloading is similar to

a) function inheritance.

b) data hiding.

c) data generalization.

d) function overloading.

Answer:

(d)

Explanation: Constructor overloading is similar to function overloading as it can also be loaded for various combinations of parameter types. The only difference is that the overloaded function can return a value but overloaded constructor cannot return a value.

Q.21 The number of constructors a class can have is

a) one.

b) two.

c) three.

d) many.

Answer:

(d)

Explanation: A class can have a number of constructors: default constructor, parameterized constructor and copy constructor.

Q.22 A global class object’s constructor is called

a) before function main begins to run.

b) after compilation.

c) before creating the class.

d) after the main function.

Answer:

(a)

Explanation: A class is created and then the object of that class is created and called before main begins to run.

Q.23 The difference between constructor function and the normal function is

a) declaration of both is different.

b) objectives are different.

c) constructor function cannot be defined in a program.

d) constructor function cannot have return type.

Answer:

(d)

Explanation: Constructor function cannot have return type, whereas destructor function has a return type.

Q.24 In the following program, an object called obj that passes the value 100 to a and 20 to c will be declared as

class sample{

int a;

char c;

public:

sample(int x, char ch)

{

a=x;

c=ch;

}

};

a) sample obj(20,100.

b) sample obj(100,20.

c) class obj(20,100.

d) class obj(100,20.

Answer:

(b)

Explanation: An object can be declared with the name same as class name. Here class name is sample and the values passed are 100 and 20.

Q.25 A constructor is called at the time of

a) beginning of the program.

b) end of the program.

c) execution of the program.

d) deletion of the program.

Answer:

(a)

Explanation: A constructor is called at the beginning of the program when the object is created.

Q.26 A destructor is called at the time of

a) beginning of the program.

b) end of the program.

c) execution of the program.

d) deletion of the program.

Answer:

(b)

Explanation: A destructor is called for a class object when that object passes out of scope or is explicitly deleted. So, it is called at the end of the program.

Q.27 In the following program, the statement which contains the error is

class num

{

int n;

public;

int num( )

{

n = 9;

}

void display()

{

cout << n;

}

};

a) public; and int num().

b) n = 9; and void display().

c) class num and n = 9;.

d) public; and n = 9;.

Answer:

(a)

Explanation: After public, there must be colon not semicolon. Constructor does not have return type.

Q.28 In the following program ,the function1 is referred as

class Readbook

{

public:

Readbook()

{cout << “Open the book” << endl;}

void Readchapter()

{cout << “Reading chapter one” << endl;)

~Readbook() //Function1

{cout << “Close the book” << endl;}

};

a) constructor

b) destructor

c) destroyer

d) structure

Answer:

(b)

Explanation: Function1 is referred to as destructor. Destructors are usually used to deallocate memory and do other cleanup for a class object and its class members when the object is destroyed.

Q.29 The output of the following program is

class sum

{

int x, y, total;

public:

sum(int a,int b)

{

x = a;

y = b*2;

}

void display()

{

total = x+y

cout << total;

}

};

void main()

{

sum S(9,5;

S.display();

}

a) 5.

b) 9.

c) 14.

d) 19.

Answer:

(d)

Explanation: Here x = 9, y = 5*2 = 10, S= 9+ 5 = 14.

Practice Questions for CUET Computer Science chapter-Constructors and Destructors SET-2

Q.30 In the following program, the function1 and function2 refers as

class science

{

char topic[20];

int weightage;

public:

science() //Function 1

{

strcpy(topic,”Optics”);

weightage = 30;

cout << “Topic Activated”;

}

~science() //Function 2

{

cout << “topic deactivated”;

}

};

a) constructor and destroyer.

b) constructor and destructor.

c) destructor and constructor.

d) public and private.

Answer:

(b)

Explanation: Member function 1 is a constructor, which initializes the class members when it invoked. Member function 2 is a destructor, which destroys the object created by the destructor.

Q.31 To simplify the process of initializing object members, C++ supports a special function called

a) inheritance.

b) file handling.

c) pointers.

d) constructor.

Answer:

(d)

Explanation: Constructor in a class is a special block of statements called when an object is created, either when it is declared or dynamically constructed on the heap through the keyword “new”.

Q.32 For the following program, the object that will invoke constructor1 will be

class Match

{

int Time;

public:

Match(int y){Time = y;} //constructor 1

Match(Match &t); //Constructor 2

};

a) class mt(a).

b) class mt(10.

c) Match mt(10.

d) Time mt(a).

Answer:

(c)

Explanation: Match is the name of the class. mt is the name of the object and the integer value passed inside it is 10.

Q.33 The constructor overloading means

a) all constructors have same structure as that of the class.

b) all constructors have same name as that of the class.

c) all constructors have same type as that of the class.

d) all constructors have same declaration as that of the class.

Answer:

(b)

Explanation: Overloading constructors, like overloading other function names, is just the practice of defining more than one constructor for a class, each taking a different set of parameters.

Q.34 To make functions inline, one should use the keyword

a) private.

b) protected.

c) inline.

d) inherited.

Answer:

(c)

Explanation: Functions defined in class are by default inline and those defined outside are not inline. Functions can be made inline by writing the keyword inline in function’s definition.

Q.35 The number of times the error value can be returned from a constructor is

a) one.

b) two.

c) never.

d) infinite.

Answer:

(c)

Explanation: An error value can never be returned from a constructor. However when a runtime error occurs, an exception can be thrown from within a constructor.

Q.36 Constructors do not have a return type because

a) constructor is not a function.

b) constructor deallocates memory.

c) constructor is called whenever an object is deleted.

d) constructor is called whenever an object gets created.

Answer:

(d)

Explanation: Constructors are called whenever an object gets created and there can never be a situation, when we want to return a value at the time of creation of n object.

Q.37 The number of times destructor can be overloaded is

a) one.

b) two.

c) zero.

d) three.

Answer:

(c)

Explanation: Destructors cannot be overloaded. There is no sense in passing any arguments to the destructors for the object whose death is certain.

Q.38 An object can be created dynamically with the help of keyword

a) dynamic.

b) create.

c) new.

d) fresh.

Answer:

(c)

Explanation: The keyword new allows us to create an object dynamically. For example: sample *p = new sample;

Q.39The member functions of a class access global data or global functions with the help of

a) ~ operator.

b) :: operator.

c) ^ operator.

d) & operator.

Answer:

(b)

Explanation: The way to access global data and functions is to use the scope resolution operator (::).

Q.40 The size of object of empty class is

a) 0 byte.

b) 1 byte.

c) 2 bytes.

d) 10 bytes.

Answer:

(a)

Explanation: The minimum amount of memory that can be reserved is 1 byte. Hence the object size turns out to be 1 byte.