UNIT-IV
UNIT-IV
UNIT-4
CONSTRUCTOR
~ tilde
E.g
#include<iostream.h>
class c
{ c()
{
public:
n=10;
cout<<n;
}
};
void main()
{
c obj;
}
TYPES OF CONSTRUCTOR
1) Default Constructor: that has no parameters, or if it has a
parameters, all the parameters have default values.
2) Parameterized Constructor: can take the arguments .
3) Copy Constructor
Default Constructor
1) Default Constructor: that has no parameters, or if it has a parameters, all the
parameters have default values.
Class student
{
int roll_no;
Public:
student(); //no parameters
Student::student()
{
-------
--------
};
Student s;
Parameterized Constructor