1.

Differentiate between a default constructor and copy constructor, giving suitable examples of each.

Answer»
Default ConstructorCopy Constructor
A constructor that accepts no parameter is called the default constructorA constructor that initializes a object with the data values of another object is called copy constructor.
A default constructor takes no parameter.Copy constructor takes one parameter of its class& type.
Example:
class Defal
{
public: Defal()
{
cout<<" Default constructor"; }
};
Example:
class A { int i;
public:
 A(int a) //constructor { i=a;
}
A(A &s)//copy constructor
{ i=s.i; }
};


Discussion

No Comment Found

Related InterviewSolutions