Page 125 - DCAP404 _Object Oriented Programming
P. 125
Object-oriented Programming
Notes abc::abc()
{
x=100;
y=200;
}
In this class constructor has been defined to have no parameter. When an object of this class is
created the programmer does not have to pass any parameter and yet the data variables x,y are
initialized to 100 and 200 respectively.
Finally, look at the class differentials as given below:
class abc
{
int x,y;
public:
abc();
abc(int);
abc(int, int);
}
abc::abc()
{
x=100;
y=200;
}
abc::abc(int a)
{
x=a;
y=200;
}
abc::abc(int a)
{
x=100;
y=a;
}
Class myabc has three constructors having no parameter, one parameter and two parameters
respectively. When an object to this class is created depending on number of parameters one of
these constructors is selected and is automatically executed.
118 LOVELY PROFESSIONAL UNIVERSITY