Object Oriented Programming approach in C++
C++ was developed by Bjarne Stroupstrup by adding OOPs concepts in C and called as C with OOPs which was later changed to C++.
What is OOPs?
OOPs stands for Object Oriented Programming System which is a system or methodology for Better Project Management using some components called pillars of OOPs
These components are
Place all the fields and methods related with an entity at one place and none of the members should be accessible outside without permission.
Use class keyword to build the encapsulation
All members inside a class are private by default.
Abstraction provides controlling by define scope on the member of a class. C++ provides three kinds of scopes
- Private (default)
To define different sections inside a class use private:, public: and protected:
Members inside a class
A class can have different members
- field -- data member
- method – function member
Methods again can be of different types
- Special methods
- General methods
Special methods again can be of two types
- A method inside a class having some features
- Same name as class
- No return type
- Used to initialize fields of an object
- Constructor can be overloaded
Passing data to the fields of an object : Data can be passed using a constructor or using a method.
Let's us see that with the help of an example