Constructor is a method which create and intialize objects.
They dont return values,constructor can be default constructor.
It just initialize members and object.Constructor is of same name
as of 'Class'.
Class employee
{
private:
int age;
char name;
public:
age 1();
name 1();
}
employee : age 1()
{
cout<<"enter age";
cin>>age;
}
main()
{
employee e= new employee();
e.age 1();
cout<<"age";
}
where 'e' is the object and 'new' for memory allocation,
we declare object and access everything through it.Default
constructor to called class employee.
They dont return values,constructor can be default constructor.
It just initialize members and object.Constructor is of same name
as of 'Class'.
Class employee
{
private:
int age;
char name;
public:
age 1();
name 1();
}
employee : age 1()
{
cout<<"enter age";
cin>>age;
}
main()
{
employee e= new employee();
e.age 1();
cout<<"age";
}
where 'e' is the object and 'new' for memory allocation,
we declare object and access everything through it.Default
constructor to called class employee.
No comments:
Post a Comment