Const member function

Write a program to show the use case of a const member function.

#include<iostream>
using namespace std;
class A
{
	private:
		int x;
		int y;
	public:
		A():x(10),y(20)
		{
			cout << "Default constructor" << endl;
		}
		void print() const
		{
			cout << "x = " << x << " y = " << y << endl;
		}
		~A()
		{
			cout << "destructor" << endl;
		}
};
int main()
{
	const A ob;
	ob.print();
	return 0;
}

Output

Default constructor
x = 10 y = 20
destructor