Simple Example Program For Parameterized Constructor In C++

Join Our Official AiJobsAdda Telegram Channel
#include<iostream>
#include<conio.h>
using namespace std;
class Example
{
// Variable Declaration
int a,b;
public:
//Constructor
Example(int x,int y)
{
// Assign Values In Constructor
a=x;
b=y;
cout<<“Im Constructor\n”;
}
void Display() {
cout<<“Values :”<<a<<”\t”<<b;
}
};
int main()
{
Example Object(10,20);
// Constructor invoked.
Object.Display();// Wait For Output Screen
getch();
return 0;
}

 

Output :
Im Constructor
Values :10
20