Default Constructor:- Default Constructor are the constructor that accept no parameter or 0 parameter.Default constructor is used in c ++,j...
Default Constructor:-Default Constructor are the constructor that accept no parameter or 0 parameter.Default constructor is used in c ++,java,c#(c sharp) etc.
Example of Default Constructors(in c++):-
#include<iostream.h>
#include<conio.h>
class swap
{
int x,y;
public:
swap() //default constructor
{
x=10;
y=20;
}
void swap()
{
x=x+y;
y=x-y;
x=x-y;
cout<<x<<y;
}};
void main()
{
class sw; //object
clrscr();
sw.swap();
getch();
}
Example of Default Constructors(in c++):-
#include<iostream.h>
#include<conio.h>
class swap
{
int x,y;
public:
swap() //default constructor
{
x=10;
y=20;
}
void swap()
{
x=x+y;
y=x-y;
x=x-y;
cout<<x<<y;
}};
void main()
{
class sw; //object
clrscr();
sw.swap();
getch();
}
If you have any query then leave your comments and don't forgot to follow me on Google+,Facebook,Twitter.
COMMENTS