Home | Computer Science

<
Constructor

Defination

A special method that is used to initialize objects.


Constructor Syntax of it is
class abc{
abc();
};
abc::abc{
}
};
Four main rules of Constructor

Basic Program
INPUT

#include <iostream> #include<conio.h> class abc{ private: int a,b,c; public: abc(); void display(); }; abc::abc{ a=10; b=20; c=30; } void abc::display{ cout<<a<<endl<<b<<endl<<c; } main() { abc a1; a1.display(); getch(); }

OUTPUT