class MyClass {
// private variables or attributes
int variable1;
float variable2;
public:
// constructor or initializer method
MyClass(int arg1, float arg2) {
variable1 = arg1;
variable2 = arg2;
}
// instance method
void instance_method() {
std::cout << "Instance method called." << std::endl;
}
// getter method
int get_variable1() const {
return variable1;
}
// setter method
void set_variable1(int arg) {
variable1 = arg;
}
// static method
static void static_method() {
std::cout << "Static method called." << std::endl;
}
};
xxxxxxxxxx
In OOP, a class is a user-defined blueprint/template and we create objects from
that class.
in OOP, an object is a instance/element of class which inherits all the Data
Members(variables) and Methods(functions) of class.
We create Objects to access data members and member functions defined in the
class.
xxxxxxxxxx
In OOP, a class is a user-defined blueprint/template and we create objects from
that class. Like if we have 100 students we can not write their rollno, name etc
100 times. We only write one time and from this template, we create 100 objects.
in OOP, an object is a instance/element of class which inherits all the Data
Members(variables) and Methods(functions) of class.
We create Objects to access data members and member functions defined in the
class.