Code of Constructor
Constructor Define Constructor:- Types of Constructor:- 1 . Default Constructor:- Constructor that is no parameter are called default constructor. #include<iostream> #include<conio.h> using namespace std; class sum { int a,b,c; public: sum() { a=10; b=20; } void add() { c=a+b; cout<<c; } }; main() { sum s1; s1.add(); getch(); } Output:- 30 2. Parameterized Constructor:- A constructor that can take arguments are called parameterized constructor. #include<iostream> #include<conio.h> using namespace std; class read { int a,b; public: read(int m , int n) { a=m; b=n; } void display() { cout<<a<<b; } }; main() { read r1(10,30); r1.display(); getch(); } output:- 10 30 Note:- If you use Dev...