Copy Constructor:- Copy Constructor are the constructor that have one argument of the object of same class. Copy constructor is used in c +...
Copy Constructor:-Copy Constructor are the constructor that have one argument of the object of same class.Copy constructor is used in c ++,java,c#(c sharp) etc.
Example of Copy Constructors(in c++):-
#include<iostream.h>
#include<conio.h>
class number
{
int a,b;
public:
number(int x,int y)
{
a=x;
b=y;
}
number(number &n) //copy constructor
{
a=m;
b=m.b;
}
void display()
{
cout<<a<<b;
}};
void main()
{
number m(20,49);
m.display();
number m1(m);
m1.display();
getch();
}
Example of Copy Constructors(in c++):-
#include<iostream.h>
#include<conio.h>
class number
{
int a,b;
public:
number(int x,int y)
{
a=x;
b=y;
}
number(number &n) //copy constructor
{
a=m;
b=m.b;
}
void display()
{
cout<<a<<b;
}};
void main()
{
number m(20,49);
m.display();
number m1(m);
m1.display();
getch();
}
If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.
COMMENTS