Constructor In C++
A constructor is a member function of a class which
initializes objects of a class. In C++, Constructor is automatically called
when object(instance of class) create. It is special member function of the
class.
·
Constructor
has same name as the class itself
·
Constructors
don’t have return type
·
A
constructor is automatically called when an object is created.
· If
we do not specify a constructor, C++ compiler generates a default constructor
for us (expects no parameters and has an empty body).
Synatx:
class class name
{
private:
----
----
public:
class name();
data member;
member function;
};
Program:
class BCA
{
private:
int a,b,c;
public:
BCA();//constructor create
void getdata();
};
Feature Of Constructor In C++
· Constructors are the special members of the class which initialize the
object of class.
- A
constructor is automatically invoked at the creation of the object.
- It is
generally used to initialize variables.
- It
has the same name as of class.
It
does not have any return type(i.e. void, int, etc).
No comments:
Post a Comment