demonstrate constructor
#include <iostream>
class MyClass {
public:
int myNum; // Declare an integer variable
// Constructor with a parameter
MyClass(int x) {
myNum = x; // Initialize myNum with the value of x
}
};
int main() {
// Create an object of MyClass
MyClass obj1(42);
std::cout << obj1.myNum << std::endl; // Output the value of myNum
return 0;
}