Question 1

Time: 00:00:00
What will be the output of the following program?

#include <bits/stdc++.h>
using namespace std;
class A{
int a;
public:
A(int i){
a = i;
}
void assign(int i){
a = i;
}
int return_value(){
return a;
}
};
int main(int argc, char const *argv[])
{
A obj;
obj.assign(5);
cout<<obj.return_value();
}

5

5

55

55

Error

Error

Segmentation fault

Segmentation fault

Garbage value

Garbage value

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 2

Time: 00:00:00
What will be the output of the following program?
#include <iostream>
#include <string>
using namespace std;
class A{
int a;
public:
A(){
cout<<"A's constructor called";
}
};
class B{
static A a;
public:
B(){
cout<<"B's constructor called";
}
static A get(){
return a;
}
};
A B::a;
int main(int argc, char const *argv[])
{
B b;
A a1 = b.get();
A a2 = b.get();
A a3 = b.get();
}

3

3

2

2

4

4

1

1

None of these

None of these

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 3

Time: 00:00:00
How many parameters does a default constructor require?

1

1

2

2

Zero(0)

Zero(0)

4

4

None of the mentioned

None of the mentioned

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 4

Time: 00:00:00
What happens if a user forgets to define a constructor inside a class?

Error occurs

Error occurs

Segmentation fault

Segmentation fault

Objects are not created properly

Objects are not created properly

Compiler provides a default constructor to avoid faults/errors

Compiler provides a default constructor to avoid faults/errors

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 5

Time: 00:00:00
How many types of constructors are there in C++?

1

1

4

4

2

2

3

3

None of the mentioned

None of the mentioned

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 6

Time: 00:00:00
Which operator a pointer object of a class uses to access its data members and member functions?

->

->

:

:

.

.

::

::

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 7

Time: 00:00:00
Which of the following statements about virtual base classes is correct?

It is used to provide multiple inheritances.

It is used to provide multiple inheritances.

It is used to avoid multiple copies of the base class in derived class.

It is used to avoid multiple copies of the base class in derived class.

It is used to allow multiple copies of the base class in a derived class.

It is used to allow multiple copies of the base class in a derived class.

It allows private members of the base class to be inherited in the derived class.

It allows private members of the base class to be inherited in the derived class.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 8

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

copy constructor

copy constructor

default constructor

default constructor

Both A and B

Both A and B

None of these

None of these

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 9

Time: 00:00:00
Which of the following statement is correct?

A destructor has the same name as the class in which it is present.

A destructor has the same name as the class in which it is present.

A destructor has a different name than the class in which it is present.

A destructor has a different name than the class in which it is present.

A destructor always returns an integer.

A destructor always returns an integer.

A destructor can be overloaded.

A destructor can be overloaded.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Question 10

Time: 00:00:00
What happens when a class with parameterized constructors and having no default constructor is used in a program and we create an object that needs a zero-argument constructor?

Compile-time error.

Compile-time error.

Preprocessing error.

Preprocessing error.

Runtime error.

Runtime error.

Runtime exception.

Runtime exception.

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

["0","40","60","80","100"]
["Need more practice! \r\n","Keep trying! \r\n","Not bad! \r\n","Good work! \r\n","Perfect! \r\n"]

Buy Capgemini Pseudo Code Paid Materials

Join Capgemini Online Classes

Personalized Analytics only Availble for Logged in users

Analytics below shows your performance in various Mocks on PrepInsta

Your average Analytics for this Quiz

Rank

-

Percentile

0%

Get over 200+ Courses under One Subscription

mute

Don’t settle Learn from the Best with PrepInsta Prime Subscription

Learn from Top 1%

One Subscription, For Everything

The new cool way of learning and upskilling -

Limitless Learning

One Subscription access everything

Job Assistance

Get Access to PrepInsta Prime

Top Faculty

from FAANG/IITs/TOP MNC's

Get over 200+ course One Subscription

Courses like AI/ML, Cloud Computing, Ethical Hacking, C, C++, Java, Python, DSA (All Languages), Competitive Coding (All Languages), TCS, Infosys, Wipro, Amazon, DBMS, SQL and others.