Aim:
To implement classes with constant data members.
Algorithm:
- Create the class called test
- Declare the integer const variable called I
- Initialization has occurred during the constructor
- It is a const data member in every object its independent copy is present.
- Initialize using constructor and the value of i cannot be changed
- Display the result.
Program:
#include<iostream> using namespace std; class data { private: const int a; public: data():a(5){} void print() { cout<<"CONSTANT VALUE :"<<a; } }; int main() { data A; A.print(); return 0; }
Execution:
INPUT : 5 OUTPUT : CONSTANT VALUE: 5
Result:
Thus, the Implementation Classes with a Constant Data Member was executed successfully.