a ____ is a member function that is automatically called when a class object is __.
a. destructor created
b. static function, deallocated
c. constructor, created
d. utility function declared
e. None of these
MCQs Answer:
c. constructor created
C++ Program to show that constructor is a member function that is automatically called when a class object is created
1 2 3 4 5 6 7 8 9 10 11 12 |
#include<iostream> using namespace std; class MCQs { public: MCQs() { cout<<"welcome to T4Tutorials.com"<<endl; } }; int main(){ MCQs x, y, z; } |
Output
Welcome to T4Tutorials.com
Welcome to T4Tutorials.com
Welcome to T4Tutorials.com
In this example we have three objects X, Y, X. so let’s see what happens.
object X
When object x is created, then MCQs() function is called and it will print “Welcome to T4Tutorials.com”.
object Y
When object Y is created, then MCQs() function is called and it will print “Welcome to T4Tutorials.com”.
object Z
When object Z is created, then MCQs() function is called and it will print “Welcome to T4Tutorials.com”.