OBJECT CREATION PROGRAM
#include <iostream>
using namespace std;
class Sample {
public:
int a;
// Constructor to initialize member variable
Sample() {
a = 10;
}
// Member function
void data() const {
cout << "adharsh" <<"\n";
}
};
int main() {
// Create an instance of the class
Sample a1;
// Access the member variable and function
cout << a1.a << std::endl;
a1.data();
return 0;
}
Comments
Post a Comment