Constructors&destructor
Constructors&destructor
Constructors&destructor
6. If you write student s[30]; where student is the name of the class ,
how many times will the constructor function be invoked
a) 29 b) 1 c) 30 d) 31
10. How many Anonymous objects can a class have at a particular time?
a) 0 b) 1 c) 2 d) N
11. Constructor and destructor are automatically invoked by
a) operating system b) compiler c) Main() d) object.
2.#include<iostream>
using namespace std;
class A
{
int x;
public:
A(int a) {
x=a;
cout<<”Constructor”<<endl;
}
~A() {
cout<<”Destructor”<<endl;
}
};
main() {
A obj1;
}
3.#include<iostream>
using namespace std;
class A
{
int x;
public:
A(a) {
x=a;
cout<<”Constructor”<<endl;
}
~A() {
cout<<”Destructor”<<endl;
}
};
main() {
A obj1;
}
4.#include<iostream>
using namespace std;
class A
{
int x;
public:
A(int a) {
x=a;
cout<<”Constructor”<<endl;
}
void get_data() {
cout<<”x=”<<x<<endl;
}
};
main() {
A obj1;
obj1.get_data();
}
5.#include<iostream>
using namespace std;
class abcd
{
~abcd() {
cout << "welcome to vector india";
}
public:
abcd() {
cout << "welcome to bangalore";
}
};
int main()
{
abcd vector;
}
6.#include<iostream>
using namespace std;
class Point
{
Point() {
cout << "Constructor called";
}
};
int main() {
Point t1;
}
7.#include<iostream>
using namespace std;
class Ex
{
public:
void ~Ex() {
cout<<"Destroying the object";
}
};
int main() {
Ex abcd;
}
8.#include<iostream>
using namespace std;
class Exam
{
public:
Exam() {
cout << "Constructor called ";
}
};
int main()
{
Exam Ex1, Ex2;
}
9.#include<iostream>
using namespace std;
class ample
{
public:
int a;
int b;
};
int main()
{
ample Ex1 = {10, 20};
cout << "a = " << Ex1.a <<", b = " << Ex1.b;
}