16.
What will be the output of this program?
#include <iostream>
using namespace std;
class sample
{
private:
int x,y;
public:
sample(int a,int b)
{ x=a; y=b;}
};
int main()
{
sample s;
return 0;
}
A. Compile Time Error
B. Run Time Error
C. No Error
D. Warning
17.
What will be the output of this program?
#include <iostream>
using namespace std;
class sample
{
private:
int x;
public:
sample(){x=0; cout<<“Object created.”;}
sample(int a){x=a;}
};
int main()
{
sample s;
return 0;
}
A. Compile Time Error
B. Object Created.
C. Run Time Error
D. Cannot be predicted
18.
What will be the output of the following program?
#include <iostream>
using namespace std;
int i;
class sample
{
public:
sample()
{
i=10;
}
};
int abc()
{
i=3;
sample ob;
return i;
}
int main()
{
cout << abc() << endl;
return 0;
}
A. 0
B. 10
C. 3
D. None of the above
19.
If the copy constructor receives its arguments by value, the copy constructor would
A. Call one-argument constructor of the class
B. Work without any problem
C. Call itself recursively
D. Call zero-argument constructor
20.
What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class A{
A(){
cout<<“A’s Constructor called\n”;
}
friend class B;
};
class B
{
public:
A a;
B(){
cout<<“B’s constructor called\ns”;
}
};
int main(int argc, char const *argv[])
{
B b;
return 0;
}
a)
A’s Constructor called
B’s constructor called
b)
B’s Constructor called
A’s constructor called
c) Error
d) Segmentation fault