• +91 9723535972
  • info@interviewmaterial.com

OOP Interview Questions and Answers

Question - What are the various types of constructors in C++?

Answer -

The most common classification of constructors includes:

Default constructor: The default constructor is the constructor which doesn’t take any argument. It has no parameters.

class ABC
{
   int x;
      
   ABC()
   {
       x = 0;
   }
}
Parameterized constructor: The constructors that take some arguments are known as parameterized constructors.

 class ABC
{
   int x;
      
   ABC(int y)
   {
       x = y;
   }
}
Copy constructor: A copy constructor is a member function that initializes an object using another object of the same class.

class ABC
{
   int x;
      
   ABC(int y)
   {
       x = y;
   }
   // Copy constructor
   ABC(ABC abc)
   {
       x = abc.x;
   }
}

Comment(S)

Show all Coment

Leave a Comment




NCERT Solutions

 

Share your email for latest updates

Name:
Email:

Our partners