CBSE - MCQ Question Banks (के. मा. शि. बो . -प्रश्नमाला )

PreviousNext

Q. 190101 A constructor function which is designed to copy objects of the same class type is called:


A. Copy constructor

B. Default constructor

C. Dynamic constructor

D. Create constructor

Right Answer is: A

SOLUTION

A copy constructor is a special constructor in C++ for creating a new object as a copy of an existing object. The first argument of such a constructor is a reference to an object of the same type as is being constructed (const or non-const), which might be followed by parameters of any type (all having default values).


Q. 190102 The initial values provided during runtime are called:


A. Passing by value

B. Object initialization

C. Dynamic initialization

D. Copy initialization

Right Answer is: C

SOLUTION

In dynamic initialization, initial values are provided during runtime. Objects can also be initialized at the runtime. The benefit of dynamic initialization is that it allows different initialization modes using overloaded constructors.

 


Q. 190103 All of the following statements about destructors are correct except:


A. Destructors do not accept any arguments, nor do they return values

B. Member functions can be called from within a destructor

C. Destructors can be inherited

D. Destructor functions are called automatically when an object is destroyed

Right Answer is: C

SOLUTION

A destructor is a special member function which is called when the lifetime of an object ends. The purpose of destructor is to free the resources that the object may have acquired during its lifetime. It never takes any argument, nor does it return any value.


Q. 190104 A constructor of a class is automatically called when


A. an object is created of that class.

B. it is a global function.

C. it calls the copy constructor.

D. it can access the constructor.

Right Answer is: A

SOLUTION

A constructor is a member function of a class that is automatically called, when an object is created of that class.


Q. 190105 The output of the following code would be:


A. Destructor A at work
Destructor B at work
Destructor C at work
Constructor A at work
Constructor B at work
Constructor C at work

B. Constructor A at work
Constructor B at work
Constructor C at work
Destructor A at work
Destructor B at work
Destructor C at work

C. Constructor A at work
Destructor A at work
Constructor B at work
Destructor B at work
Constructor C at work
Destructor C at work

D. Constructor A at work
Constructor B at work
Constructor C at work
Destructor C at work
Destructor B at work
Destructor A at work

 

Right Answer is: D

SOLUTION

In the given program, the constructor A is invoked first, followed by constructors of classes B and C. The destructors however are invoked in the reverse order of derivation. The destructor of class C, which is the most derived class, is invoked first and then destructors of B and A are invoked respectively. Output:


Q. 190106 The correct statement about constructors is:


A. A constructor has a return type

B. A constructor cannot contain a function call

C. A constructor has a void return type

D. A constructor has no return type

Right Answer is: D

SOLUTION

A constructor is a member method with the same name as its class. It is used to initialize the objects of that class type with a legal initial values. A constructor is not called like other functions so they don't have return types like other functions.


Q. 190107 Identify the error in the following code:
class ITEM{ int code;
char shelf;
ITEM(char s) { shelf=s;}
};
void main(){
ITEM I(‘F’);
}


A. Destructor is missing

B. Constructor cannot assign values to data members

C. Object cannot be created in main() as constructor is private

D. The object in main() does not call any function

Right Answer is: C

SOLUTION

We generally want the constructor and destructor to be made public so that the class can be created. The constructor is called when an object is created but if the constructor is private, it cannot be called so the object cannot be constructed. This will cause the compiler to complain. 


Q. 190108 The number of default constructors per class are possible:


A. Two

B. Only one

C. Three

D. Unlimited

Right Answer is: B

SOLUTION

Default constructor is a constructor with no arguments. Only one constructor is required to initialize the object.


Q. 190109 The output of the following code would be:


A. 3

B. 0

C. 10

D. 1

Right Answer is: A

SOLUTION

While returning from a function, destructor is the last method to be executed. The destructor for the object 'ob' is called after the value of 'x' is copied to the return value of the function. Thus, before destructor could change the value of 'x' to 10, the current value of 'x' gets copied and hence the output is 'x = 3'.
Output:


Q. 190110 For a class named BOOK, the statement Book(); is a/an:


A. Inline constructor

B. Explicit call to the constructor

C. Implicit constructor

D. Default constructor

Right Answer is: D

SOLUTION

A default constructor (non-parameterized constructor) does not contain any arguments.


Q. 190111 A parameterized constructor


A. can accept a number of arguments

B. can accept only one argument

C. accepts no arguments

D. always accept reference to an object

Right Answer is: A

SOLUTION

Parameterized constructors allow us to create a new instance of a class while simultaneously passing arguments to the new instance.


Q. 190112 Given a class named Student, which one of these constructor declaration is valid for the class Student?


A. private final Student(){}

B. void final Student(){}

C. Student(Student s){}

D. abstract Student(){}

Right Answer is: C

SOLUTION

A constructor cannot specify any return type not even void. A constructor cannot be final, static or abstract. 


Q. 190113 The copy constructor for class Student is:


A. (&Student)

B. (Student&)

C. Student(&Student)

D. Student(Student&)

Right Answer is: D

SOLUTION

A copy constructor is used to copy an object to a newly created object. That is, it is used during initialization, including passing function arguments by value and not during ordinary assignment. A copy constructor for a class normally has this prototype:
class_name (const class_name&);
Therefore, the copy constructor for class Student would be Student(Student&)
 


Q. 190114 Constructor overloading means


A. constructors having same structure as that of the class.

B. constructors having same name as that of the class, but different parameters.

C. constructors having same type as that of the class.

D. constructors having same declaration as that of the class.

Right Answer is: B

SOLUTION

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. 190115 To simplify the process of initializing object members, C++ supports a special function called


A. inheritance.

B. file handling.

C. pointers.

D. constructor.

Right Answer is: D

SOLUTION

Constructor in a class is a special member function that is called when an object is created.


Q. 190116 A destructor is called at the time of the


A. beginning of the program.

B. end of the program.

C. execution of the program.

D. deletion of the program.

Right Answer is: B

SOLUTION

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. 190117 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.

Right Answer is: A

SOLUTION

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


Q. 190118 The difference between constructor and a normal function is that


A. declaration of both is different.

B. objectives are different.

C. constructor cannot be defined in a program.

D. constructor does not have return type.

Right Answer is: D

SOLUTION

Constructor does not have a return type, whereas a normal function has a return type. If a function is not returning any value, then "void" must act as its return type.


Q. 190119 To create object in any function, define it under


A. public.

B. private.

C. protected.

D. friend.

Right Answer is: A

SOLUTION

Generally, a constructor should be defined under the public section of a class, so that its objects can be created in any function.


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


A. one.

B. five.

C. seven.

D. unlimited.

Right Answer is: D

SOLUTION

A class can define numerous constructors. It can be of the following types : a) default constructor, b) parameterized constructor c) copy constructor.


Q. 190121 Constructor overloading is similar to


A. function inheritance.

B. data hiding.

C. data generalization.

D. function overloading.

Right Answer is: D

SOLUTION

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


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


A. one.

B. two.

C. three.

D. infinite.

Right Answer is: B

SOLUTION

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


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


A. copy constructor.

B. parameterized constructor.

C. default constructor.

D. destructor.

Right Answer is: B

SOLUTION

Parameterized constructors take values as arguments into the constructor function when the objects are created.


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


A. static initialization.

B. dynamic initialization.

C. public initialization.

D. private initialization.

Right Answer is: B

SOLUTION

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


Q. 190125 The feature of constructor which is more beneficial than default argument is


A. overloading.

B. encapsulation.

C. data hiding.

D. abstraction.

Right Answer is: A

SOLUTION

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. 190126 Private and protected constructors are available for


A. member functions only.

B. friend functions only.

C. member and friend function.

D. public function.

Right Answer is: C

SOLUTION

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


Q. 190127 The property of destructors is that


A. it can return any value.

B. an argument can be provided to it.

C. it cannot be inherited.

D. it is possible to print the address of a destructor.

Right Answer is: C

SOLUTION

Destructors cannot be inherited, though a derived class can call the base class constructor.


Q. 190128 A destructor is preceded by the symbol


A. ~.

B. !.

C. ^.

D. $.

Right Answer is: A

SOLUTION

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


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


A. destroyer.

B. destructor.

C. deinitializer.

D. constructor.

Right Answer is: B

SOLUTION

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. 190130 A constructor that initializes an object with the data values of another object is known as


A. virtual constructor.

B. copy constructor.

C. default constructor.

D. same constructor.

Right Answer is: B

SOLUTION

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 ,i.e., a reference to the object to be copied.


Q. 190131 The name of a constructor is the same as the name of the


A. helper function.

B. class.

C. friend function.

D. main function.

Right Answer is: B

SOLUTION

A constructor is a member function which is always declared with the same name as its class.


Q. 190132 An anonymous shortlived object is known as


A. constructor object.

B. temporary object.

C. permanent object.

D. public object.

Right Answer is: B

SOLUTION

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. 190133 Copy constructor is called


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.

Right Answer is: B

SOLUTION

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. 190134 The destructor is a:


A. Member function that destroys the class

B. Member function that destroys constructors

C. Member function that destroys objects

D. Member function that destroys both constructors and objects

Right Answer is: C

SOLUTION

A destructor is a function with the same name as that of class name preceded by a tilde sign (~). It is a member function which is used to destroy the objects that have been created by a constructor.


Q. 190135 If a class is named as FSH:


A. The constructor will be FSH and destructor will be ~FSH

B. The constructor will be ~FSH and destructor will be FSH~

C. The constructor will be FSH( )and destructor will be ~FSH

D. The constructor will be FSH( ) and destructor will be ~FSH( )

Right Answer is: D

SOLUTION

A constructor is a member method with the same name as its class. A destructor is a function with the same name as that of class name preceded by a tilde sign (~). Thus, if a class is named FSH: the constructor will be FSH () and the destructor will be ~FSH()


Q. 190136 The copy constructor is invoked:


A. When an object is passed as a parameter to a function by reference

B. When a function returns an object by value

C. When one object is assigned to another object

D. When a function does not return an object by value

Right Answer is: B

SOLUTION

The copy constructor is invoked when an object is passed by value to a function. It creates the copy that the function operates on.    


Q. 190137 The output of the following program would be: #include < iostream.h >
using namespace std;
class Point {
public:
Point()
{
cout << "Constructor called";
}
};
int main()
{
Point t1, *t2;
return 0;
}


A. Destructor called

B. Constructor called

C. Runtime error

D. Compile time error

Right Answer is: B

SOLUTION

Only one object t1 is constructed here. t2 is just a pointer variable and not an object.


Q. 190138 If the class does not have a constructor then the:


A. Objects cannot be created for it

B. Objects will be created but not initialized

C. Compiler will be display an error message

D. Compiler creates one

Right Answer is: D

SOLUTION

Compiler generates an implicit default constructor when explicit default constructor is not specified.


Q. 190139 The constructor may be called:


A. Implicitly

B. Explicitly

C. Implicitly and explicitly

D. As a copy

Right Answer is: C

SOLUTION

A constructor can be called implicitly and explicitly.


Q. 190140 A constructor with no arguments is called:


A. Overloaded constructor

B. Copy constructor

C. Multiple constructors

D. Default constructor

Right Answer is: D

SOLUTION

A constructor with no arguments is called default constructor or non-parameterized constructor. They are automatically called when object of the class is created.


Q. 190141 The number of constructors that can be present in a class:


A. multiple

B. 1

C. 2

D. 3

Right Answer is: A

SOLUTION

There can be multiple constructors of the same class, provided they have different signatures.


Q. 190142 The name of the constructor is the same as the:


A. Name of the object

B. Name of the class

C. Name of the public member functions

D. Name of the private data members

Right Answer is: B

SOLUTION

Constructor is a member method with the same name as its class. It is used to initialize the objects of that class type with a legal initial values.

 
 


Q. 190143 A parameterized constructor can take:


A. Arguments

B. Only one argument

C. No arguments

D. Reference to an object

Right Answer is: A

SOLUTION

The constructor that takes arguments is called a parameterized constructor. A parameterized constructor contains arguments to assign the values to the class elements.


Q. 190144 If a constructor is defined privately:


A. Objects will be created only in non member functions

B. Only global objects will be created

C. Objects will be created only in member functions

D. It will not be possible to create objects

Right Answer is: C

SOLUTION

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. 190145 A constructor is a special function that can:


A. Return only integer values

B. Return an object of the same class

C. Return any value

D. Never return a value

Right Answer is: D

SOLUTION

A constructor is a special function that can be used once and never returns a value. It is used to initialize the objects of that class type with a legal initial values.


Q. 190146 A default constructor:


A. Can take any number of arguments

B. Can take only one argument

C. Contains no arguments

D. Can take as many arguments as the objects

Right Answer is: C

SOLUTION

A default constructor (non - parameterized constructor) does not contain any arguments. It is called when an object is declared but is not initialized with any arguments.


Q. 190147 A constructor


A. creates class members

B. initializes objects

C. initializes classes

D. creates default constructs

Right Answer is: B

SOLUTION

constructor is a special member function which is used to initialize the member of the class.


Q. 190148 If a class is named FSH,


A. the constructor will be FSH and destructor will be ~FSH

B. the constructor will be ~FSH and destructor will be FSH~

C. the constructor will be FSH( )and destructor will be ~FSH

D. the constructor will be FSH( ) and destructor will be ~FSH( )

Right Answer is: D

SOLUTION

Constructors and destructors are special member functions of classes that are used to construct and destroy class objects respectively. Construction may involve memory allocation and initialization for objects. Destruction may involve cleanup and deallocation of memory occupied by objects.


Q. 190149 A default constructor


A. can take any number of arguments

B. can take only one argument

C. cannot take any arguments

D. can take as many arguments as the objects

Right Answer is: C

SOLUTION

A default constructor is a constructor that accepts no parameter.If a class has no explicit constructor defined, the compiler will supply a default constructor.


Q. 190150 A constructor


A. creates class members.

B. initializes objects.

C. initializes classes.

D. creates default constructs.

Right Answer is: B

SOLUTION

Constructor is a special member function used to initialize members of an object.


Q. 190151 If the class does not have a constructor,


A. objects cannot be created for it.

B. objects will be created but not initialized.

C. the compiler will display an error message.

D. the compiler creates one.

Right Answer is: D

SOLUTION

This is called default constructor, which is automatically created by compiler.


Q. 190152 A constructor may be called


A. implicitly.

B. explicitly.

C. implicitly or explicitly.

D. as a copy.

Right Answer is: C

SOLUTION

We call a constructor explicitly by giving different number of parameters, but otherwise if we provide no parameters or arguments, default constructor is automatically called.


Q. 190153 Initial values being provided during runtime is called


A. passing by value

B. objects initialization

C. dynamic initialization

D. copy initialization

Right Answer is: C

SOLUTION

values could be assigned at compile-time as well as run-time. If assignment will be done at run-time then it is known as dynamic initialization.


Q. 190154 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).

Right Answer is: C

SOLUTION

Match is the name of the class and mt is the name of the object. Integer value i.e. 10 passed to the object.


Q. 190155 In the following program, 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.

Right Answer is: B

SOLUTION

function1 is a constructor which initializes the class members when it is invoked. function2 is a destructor which destroys the object created by the destructor.


Q. 190156 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.

Right Answer is: D

SOLUTION

Here x = 9, y = 5*2 = 10, total = 9+ 10 = 19. So 19 will be displayed.


Q. 190157 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.

Right Answer is: B

SOLUTION

function1 is referred to as destructor. Destructors are usually used to deallocate memory as the object goes out of scope.


Q. 190158 In the following program, the statement which generates 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;.

Right Answer is: A

SOLUTION

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


Q. 190159 In the following program, an object named 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).

Right Answer is: B

SOLUTION

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


Q. 190160 The name of constructor and destructor in 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().

Right Answer is: A

SOLUTION

constructor and destructor have the same name as that of a class. Destructor is always preceded by tilde(~) symbol.


Q. 190161 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.

Right Answer is: C

SOLUTION

double sample(); is not correct as constructor does not have any return type.


Q. 190162 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.

Right Answer is: A

SOLUTION

At first main() will be executed. Inside main(), Time is called then distance, then distance under class figure is called, then Time and finally figure.


Q. 190163 The destructor automatically executes when the class object goes out of


A. use.

B. class.

C. scope.

D. call.

Right Answer is: C

SOLUTION

Destructor is always executed automatically whenever the class object goes out of scope.


Q. 190164 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.

Right Answer is: A

SOLUTION

Constructors that take arguments are known as parameterized constructors.


Q. 190165 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. 
According the the above statement, true statement among the following option is


A. if the class designer wants to allow 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.  

Right Answer is: A

SOLUTION

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. 190166 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.

Right Answer is: D

SOLUTION

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. 190167 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( ).  

Right Answer is: B

SOLUTION

class weight
                    {                           int x, y;                           public:                                   weight( ) { }                                   ~weight( )  { }                      };


Q. 190168 For the following program, the object that will invoke constructor1 will be -
          class Pilot          {           int num;           public:           Pilot(int y){num = y;}    //constructor1           Pilot(Pilot &t);               //constructor2            };  


A. class pt(a)

B. class pt(10)

C. Pilot pt(10)

D. num pt(a)

Right Answer is: C

SOLUTION

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


Q. 190169 The object which will invoke constructor1 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);

Right Answer is: D

SOLUTION

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


Q. 190170 In the following C++ code, function 1 is referred to as            class TestMeOut             {                 public:                       ~TestMeOut( )    //function1                       {                            cout <<  “Leaving the examination hall”  << endl;                       }                        TestMeOut( )    //function2                       {                            cout  <<  “Appearing for examination”  << endl;                       }                       voidMyWork( )   //function3                      {                           cout <<  “Attempting Questions”  <<  endl;                      }               };


A. constructor.

B. private member.

C. destructor.

D. public member.

Right Answer is: C

SOLUTION

function1 is destructor and it will get invoked as the scope of object gets over.


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


A. destructor.

B. destroyer.

C. constructor.

D. temporary object.

Right Answer is: C

SOLUTION

In object-oriented programming, a constructor is a special block of statements that initializes the values of members of a class. It always declared with the same name as the class is.


Q. 190172 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.

Right Answer is: C

SOLUTION

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


Q. 190173 The order of invocation of constructors for the following programs is
          class Universe          {                 Universe() {  ...  }           };          class Earth          {                 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.

Right Answer is: A

SOLUTION

At first main() function will be executed. Inside main(),Earth is called then Universe, then Universe under class India is called, then Earth and finally India.


Q. 190174 Destructor is a member function that destroys


A. the class.

B. constructors.

C. objects.

D. pointers

Right Answer is: C

SOLUTION

A destructor is a method that is automatically invoked, when an object is destroyed. Its main purpose is to deallocate the memory space occupied by objects when it goes out of scope.


Q. 190175 A constructor


A. cannot take arguments

B. cannot have default values

C. can be inherited

D. cannot have a return type

Right Answer is: D

SOLUTION

Constructor is a function whose name is same as the object, with no return type (not even void).


Q. 190176 If a constructor is defined privately,


A. objects will be created only in non member functions.

B. only global objects will be created.

C. objects will be created only in member functions.

D. it is not possible to create objects.

Right Answer is: C

SOLUTION

Generally, a constructor should be defined under the public section of a class, so that its object can be created in any function. If a constructor is defined privately then objects will only be created in member functions.


Q. 190177 A constructor is a special member function that


A. returns only integer values

B. returns an object of the same class

C. returns float value

D. never return a value

Right Answer is: D

SOLUTION

Constructor is a special member function that never return a value.


Q. 190178 A constructor with default arguments is equivalent to a


A. parameterized constructor

B. default constructor

C. empty constructor

D. null constructor

Right Answer is: B

SOLUTION

A constructor with default arguments is equivalent to a default constructor.


Q. 190179 A constructor with default arguments


A. is equivalent to an overloaded constructor

B. is equivalent to a copy constructor

C. is equivalent to multiple constructors

D. is equivalent to a default constructor

Right Answer is: D

SOLUTION

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


Q. 190180 If the constructor is declared under public section,


A. objects will be created in non member functions

B. objects will be created only in friend functions

C. objects will be created only in member functions

D. it will not be possible to create objects

Right Answer is: A

SOLUTION

The constructor is usually called when the Object is instantiated/created.


Q. 190181 How is the constructor different from other member functions?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

The constructor is a special function of the class. Some of the features that differentiate it from others functions -



I
t is the one invoked automatically when the object is created. 

It has the same name as the class.  

It cannot return a value. 


Q. 190182 What are destructors?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

Destructors are special member functions that are invoked automatically when an object is to be destroyed.  The name of the destructor is same as the class, preceded by a ~(tilde) character.


Q. 190183 What is meant by the term copy initialization?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

Initializing objects through the copy constructor is called copy initialization.

In the example, for a class ABC, the statement below creates object ob2 initialized with the object ob.

               ABC ob2(ob);          // copy constructor called           


Q. 190184 What is a temporary instance?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

A temporary instance is the one that lives in the memory as long as it is being used or referenced in an expression and after this it dies.


Q. 190185 What are parameterized constructors?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

A constructor that takes arguments is a parameterized constructor. 

Example :

 

class ABC{

     int a;

     int b;

   public:

    ABC( int x, int y){a=x; b=y;}     // parameterized constructor

     ……..

};

void main(){

  ABC ob2(2,3);       // parameterized constructor invoked

   ……..

}                 


Q. 190186 What is a default constructor?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

A constructor that does not accept any argument is a default constructor.  

Example:
Default constructor for STUDENT class -
           STUDENT( )  {rno=0;}


Q. 190187 What purpose does a constructor serve?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

The constructor provides some valid initial values to the created object.


Q. 190188 What is a constructor ?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

A constructor is a member function of a class that is invoked automatically when an object of that class is created.  It has the same name as the class and initializes the object with legal initial values.          


Q. 190189 When the compiler can provide a constructor, why do we define it?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

The compiler provides its own values, which are legal.  By defining the constructor, we can provide values according to our requirement.


Q. 190190 What conditions a function need to satisfy in order to create objects of a class?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

A function can create objects of a class if it can access the constructors.


Q. 190191 Write a short note on the significance of the destructors.
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

An object that is existing must be scrapped off when it is no more needed. The task of scrapping off an object is carried out by a destructor. A destructor deinitializes an object and deallocates all allocated resources.             


Q. 190192 How many times does the copy constructor called in the following code, using class A :       A func(A x){     A y(x);     A  z = y;     return z; }   void main( ) {    A a;    A b = func(a);    A c = func(b); }                                 
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

The copy constructor is called 8 times -
  

1.  object a passed by value to func( )

2.  object y initialized in func ( ) with x

3.  object z initialized in func ( ) with y

4.  object z returned

5.  object b passed by value to func( )

6.  object y initialized in func ( ) with x

7.  object z initialized in func ( ) with y

8.  object z returned                                    


Q. 190193 How are the two statements given below different?       Shape s1(10,5);                               //statement 1     Shape s1 = Shape(10,5);              // statement 2 
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

In both the statements, an object, s1 is created.  In statement 1, the constructor is called implicitly.  In statement 2, the constructor is called explicitly, by name.                             


Q. 190194 Why does destructors are required?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

An object created in a program must be destroyed when it is no more needed.  This task is done by the destructor.  It deallocates the memory space and resources acquired by an object.


Q. 190195 What do you understand by dynamic initialization of objects? 
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

Dynamic initialization means that initial values for the object may be provided at runtime.  In the example, values to be passed as arguments are received at run time.

 

class ABC { int a;

                int b;

  public:

        ABC( int x, int y)  { a=x; b=y; }

..

};

void main( ){

    int x, y;

    cout<<”Enter integer values for x and y “;

    cin>>x>>y;

    ABC ob ( x, y);

   

}       


Q. 190196 What will be the order of invocation of constructors for the following code?      class X{………}; class Y { ….. }; class Z { …..         public:                 Z ( );                 X ox;                 Y oy; }; void main() {          X x1;          Y y1;          Z z1;     }                     
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

The order of invocation will be –

1.  X :: X( ) for x1

2.  Y :: Y( ) for y1

3.  X :: X( ) for ox in z1

4.  Y :: Y( ) for oy in z1

5.  Z :: Z( ) for z1 


Q. 190197 Why is the object passed by reference to a copy constructor?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

This is because, when an argument is passed by value, its copy is made. To make a copy of an object, the copy constructor is called.  Thus, it calls itself again.  In fact, it calls itself over and over again until the compiler, goes out of memory. So, the object is passed by reference which doesn't create copy.     


Q. 190198 What are copy constructors?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

A copy constructor is a constructor of the form classname( classname &). the compiler will use the copy constructor whenever you initialize an instance using values of another instance of same type. 
For Example -


Sample s1;        //default constructor


Sample s2=s1;   //copy constructor


Q. 190199 Explain constructor overloading with examples.
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

Overloaded function refer to the same function performing different activities depending on the values passed to it.  Constructor too is a function, and it can be overloaded.  Multiple constructors can be defined and different number and types of values can be sent for initialization.  Example :

 

class A{

     int a;

     int b;

   public:

     A ( ) {a=0; b=0;}                           //default constructor

     A( int x, int y){a=x;b=y;}            //constructor with 2 arguments

     A(int x){a=x; b=2*x;}               //constructor with 1 arguments

};

void main(){

  A ob;                          // will invoke the default constructor

  A ob2(2,3);                // constructor with two arguments invoked

  A ob3(6);                   // constructor with one arguments invoked

}                                                                                                         


Q. 190200 What are the main characteristics of destructors?
A. objects will be created in non member functions
B. objects will be created only in friend functions
C. objects will be created only in member functions
D. it will not be possible to create objects

Right Answer is:

SOLUTION

Destructors too are special member functions.  Their characteristics are – 


 
1.  They have the same name as the class, preceded by the ‘~’ character (tilde).

 2.  They are invoked automatically when objects are destroyed.

 3.  No return type is specified for destructors

 4.  Destructors obey the access rules. 

 5.  They cannot be static.

 6.  They cannot be inherited. 

 7.  Arguments cannot be passed to a destructor.

 

 


PreviousNext