Site icon T4Tutorials.com

Which of the following is not a type of constructor?

Question: Which of the following is not a type of constructor?
a. Friend constructor
b. Copy constructor
c. Default constructor
d. Parameterized constructor
Answer:
Friend constructor


Friend constructor is not a constructor but the Friend function exists in C++.

C++ Program of Friend function

Friend Class in CPP

#include <iostream>    
using namespace std;    
class Room    
{    
    private:    
        int width;    
    public:    
        Room(): width(0) { }    
        friend int printWidth(Room); //friend function    
};    
int printWidth(Room b)    
{    
   b.width += 10;    
    return b.width;    
}    
int main()    
{    
    Room b;    
    cout<<"Width of Room: "<< printWidth(b)<<endl;    
    return 0;    
}    

 

Types of constructors in C++

C++ has 3 types of constructors;

  1. Copy constructor
  2. Default constructor
  3. Default constructorTypes of constructors

C++ Program of Copy constructor & parameterized constructor

#include <iostream>  
using namespace std;  
class t4tutorials  
{  
   public:  
    int num;  
    t4tutorials (int a)                // parameterized constructor.  
    {  
      num =a;  
    }  
t4tutorials (t4tutorials &i)               // copy constructor  
    {  
        num = i. num;  
    }  
};  
int main()  
{  
  t4tutorials abc(44);               // Calling the parameterized constructor.  
 t4tutorials xyz(abc);                //  Calling the copy constructor.  
 cout<<xyz. num;  
  return 0;  
}  

C++ Program of Copy constructor & parameterized constructor

// Cpp program to show Default Constructor 
#include <iostream> 
using namespace std; 
  
class BSCS { 
public: 
    int x, y; 
  
    // Default Constructor 
    BSCS() 
    { 
        x = 44; 
        y = 55; 
    } 
}; 
  
int main() 
{ 
    // Default constructor called automatically 
    // when the object is created 
    BSCS t4tutorials; 
    cout << "x: " << t4tutorials.x << endl 
         << "y: " << t4tutorials.y; 
    return 1; 
}

1000+ Programming C Plus Plus MCQs

Highly Recommended C++  Important MCQs with Explanation

  1. Which symbol is used to create multiple inheritances?
  2. If a derived class object is created, which constructor is called first?
  3. Which of the following is not a type of constructor?
  4. a ____ is a member function that is automatically called when a class object is __.
  5. What is the output of the following code in C++?
  6. How many times will the following code print?
  7. Which of the following is a procedural language?
  8. Which of the following is not a programming language?
  9. Which of the following is not an example of high-level language?
  10. While declaring pointer variables which operator do we use?
  11. To which does the function pointer point to?
  12. Which of these best describes an array?
  13. Which of the following is a Python Tuple?

Other important MCQs

Data Structure

Which of the following is not the type of queue?
Database

If one attribute is a determinant of the second, which in turn is a determinant of the third, then the relation cannot be
Python
Which of the following is a Python Tuple?

Exit mobile version