PARAMETERIZED CONSTRUCTOR:
The constructor with the arguments is called parameterized constructor.
For example program:
The constructor with the arguments is called parameterized constructor.
For example program:
#include<iostream>
#include<conio.h>
class gasc
{
// Variable Declaration//
int a, b;
public:
//Constructor//
gasc(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() {
gasc Object(5,10);
Object.Display(); //constructor invoked//
getch();
return 0;
}
Output:
Im Constructor
Values :5 10
Comments
Post a Comment