Object Orientated Programming in C++

The reason why C++ is known for it’s high performance in modern software applications, is because of it’s support of being an object-orientated language. This means that the foundations laid out of any program created in C++ might be visualized in term of Objects. Object Orientated Programming in C++ allows developers to think of real life things, turn them into objects and solve issues with those objects. Other languages which are also known for OOP are Java, C#, Visual Basic, Object C and Visual Basic.

Imagine if you are writing a small program which stores the details of a car. The first thing we’re able to do is to brainstorm and jot down the details of a car that come to mind. 3 examples that instantly come to mind and can be used as objects in creating a class are:

1) Passengers

2)Fuel Capacity

3)Engine Type

All these three examples above can be represented as objects in a C++ Class. What we can do now is set a variable type to each object and build the class. How would the objects from the car example look like in code?

car class exampleWith the small code example above, we have easily created a class called Car, containing the three object examples that were brainstormed into which have now been declared as variable object types of the Car class. As you can see there is a keyword called “public” in the class. This keyword as well as two other ones show up very frequently when creating classes and it’s important to understand them.

What is the difference between public, private and protected keyword?

Public members can be accessed anywhere if the object is able to be found.

Private members, no one other than the own class can access the members.

Protected members can only be accessed by its own class and its shared members in inheritance of classes(advance topic).

Share this post