Constructors and Destructors - Programs Multiple Questions and Answers.
Exercise Questions ::
Constructors and Destructors
1. | What will be the output of the program? |
|
#include<iostream.h>
class PakMcqs
{
int x;
public:
PakMcqs(int xx, float yy)
{
cout<< char(yy);
}
};
int main()
{
PakMcqs *p = new PakMcqs (35, 99.50f); return 0; }
|
| A. | 99.50 |
| B. | Garbage value |
| C. | ASCII value of 99 |
| D. | 99 |
|
|
Published by:Michael Daani
2. | Which of the following statement is correct about the program given below? |
|
#include<iostream.h>
class PakMcqs
{
public:
PakMcqs()
{
cout<< "Pak";
}
~PakMcqs()
{
cout<< "Mcqs";
}
};
int main()
{
PakMcqs objmcqs;
return 0;
}
|
| A. | The program will print the output Pak |
| B. | The program will print the output Mcqs |
| C. | The program will print the output PakMcqs |
| D. | The program will report compile time error. |
|
|
Published by:Michael Daani
3. | Which of the following statement is correct about the program given below? |
|
#include<iostream.h>
class Mcqs
{
int x;
public:
Mcqs();
~Mcqs();
void Show() const;
};
Mcqs::Mcqs()
{
x = 25;
}
void Mcqs::Show() const
{
cout<< x;
}
int main()
{
Mcqs objB;
objB.Show();
return 0;
}
|
| A. | The program will print the output 25. |
| B. | The program will print the output Garbage-value. |
| C. | The program will report compile time error. |
| D. | The program will report runtime error. |
|
|
Published by:Michael Daani
4. | Which of the following statement is correct about the program given below? |
|
#include<iostream.h>
class PAK
{
int x;
public:
PAK();
void Show() const;
~PAK(){}
};
PAK::PAK()
{
x = 5;
}
void PAK::Show() const
{
cout<< x;
}
int main()
{
PAK objB;
objB.Show();
return 0;
}
|
| A. | The program will print the output 5. |
| B. | The program will print the output Garbage-value. |
| C. | The program will report compile time error. |
| D. | The program will report runtime error. |
|
|
Published by:Michael Daani
5. | What will be the output of the program ? |
|
#include<iostream.h>
int val = 0;
class PAKMCQS
{
public:
PAKMCQS()
{
cout<< ++val;
}
~PAKMCQS()
{
cout<< val--;
}
};
int main()
{
PAKMCQS objPAK1, objPAK2, objPAK3;
{
PAKMCQS objPAK4;
}
return 0;
}
|
| A. | 1234 |
| B. | 4321 |
| C. | 12344321 |
| D. | 12341234 |
|
|
Published by:Michael Daani