What is OOP?
OOP (object-oriented programing) is a structure or paradigm based on an object that represents or contains the whole data of a class in the form of data and methods. The concepts of OOP are,
- Class: class is a user-defined structure that contains data members and member functions and provides various functionalities in a single block of statements.
- Object : Object represents class. In the object, data and methods of any class are combined, and you can access any data or method of class using its respective object. For performing any operation on class data, the object is commonly used.
- Encapsulation: Encapsulation refers to the wrapping of various data into a single unit. Encapsulation does wrapping of data which helps to access it easily. Class is the best example of encapsulation where data members and member functions get wrapped up into a single unit known as an object, making it easier to access.
- Inheritance: Inheritance means accessing data members and member functions of one class into another class or accessing data members and member functions of parent class by child class is known as inheritance. There are five types of inheritance,
- Polymorphism: Polymorphism can provide various functionalities with the same
- Abstraction: Abstraction is the method where the complexity of code is hidden. This shows only the easy part to the user and reduces the complexity.
using namespace std;
// The class
public: // Access specifier
int x; // Attribute (int variable)
string str; // Attribute (string variable)