CONSTRUCTOR:
Constructor are the special member function of the class which are used to initialize the objects of that class. The constructor of class is automatically called after the creation of the object. Name of the constructor should exactly same as that of name of the class. Constructor is called once in a lifetime of object when object is created.
PROGRAM:
#include<iostream.h>
using namespace std;
class Marks{
public:
int math, science;
Marks()
{
maths=65;
science=80;
}
void Display()
{
cout<<"Maths="<<maths;
cout<<endl<<"Science="<<science;
}
};
int main()
{
Marks m;
m.Display();
return 0;
}
No comments:
Post a Comment