what is OOPs in cpp

In this, we will discuss C ++ OOPs concept and their features,

Introduction oops in C ++

C ++ is the only updated version of C language as we know, but why C ++ was needed when C language was already there. The main difference between C and C ++ is that of OOPs.

C is a POP (Procedure Oriented Programming) language whereas C ++ is the Object Oriented Programming language. However, C ++ supports both OOPs and POPs while C supports only POPs.

When OOPs features were added to C, it was named C ++. Before programming in OOP, let’s learn about POP and OOPs so that you know why a new language, C ++, was missing.

Procedure Oriented Programming (POP)

POP language is a collection of function or set of function. In programming language based on this type of technique, a program is divided into several functions. These functions contain statements for an operation.

But when the number of functions in a program starts increasing or the size of the program increases, in such a situation it is not easy to manage such a large code and thus the function declared in the program accesses the global data. But in such a large number where functions are accessing the same data, then problems like data -loss or data -flow start occurring and due to which the program does not give a suitable result. In other words, we can say that there are bugs or errors in the program.

It is not easy to debug such a large program, which is divided into many functions. We have to determine each function, which is a complex process. C, pascal, cobol are examples of language of POP type.

Object-Oriented Programming (OOPs)

In simple words, OOPs are collection of objects. In which the program is divided into object where the object is a collection of data -member function member which together are logically related to each other as a set, which is called class. Therefore we can say that a class is an important feature of OOPs.

Let’s understand it in detail –

Just as POPs based language is a collection of function, oops is the language set of object, in which the program is divided into object to perform the real -world problem or task.

As stated, there is a set of object data members and function member called class, these members cannot be accessed from outside or from any external function. In a way, data remains secure, and because only objects of the same class can access these functions, the probability of data flow also decreases.

Also provides the facility to reuse class members in OOPs. C ++, Java, Smalltalk language support OOPs programming. Because C ++ supports both POP and OOP, it is not pure OOPs language.

C ++ supports both pop and oop, which means that you can be programming it in both pop and oop. All the programs given so far in this tutorial are examples of pop programming.

Before starting oops we will discuss about other features of OOPs.

These features are

class in C ++

The class is a user-defined data type. The most important features of class oops are the same as other features of oops are implemented.

A class is a collection of data member and function member, which can be of both data types (int, float, char) and derived data types (array, function). In which members are logically related to each other. These data members can only be accessed by the function members of this class. That is, the data cannot be accessed from outside the class. In a way, data security is achieved.

The syntax of a class would be as follows –

class class-name 

Where class-name is an identifier ie any user defined name (except reserved keyword)

Using this syntax of the class, we can create a class, but cannot implement it, that means if we create a class with this syntax in mind, there will be no runtime error in it, but there is no output Neither will come.

So the class has some access specifier. Using which we implement a class. So the new syntax will be as follows –

class class_name
   private:    //access specifier
      data member;
      function member; 

   public:    // access specifier
      data member;
      function member;

We will read more about the class further.

When we use a class in the program, we get other features of OOPs like encapsulation, data abstraction, data encapsulation.

Let’s discuss them,

object in C ++

Just as in the real world an object has its own property or behaviour, similarly in OOPs, the property of an object, the function member of that class and the behaviour is the data member of that class.

The object is a set of data members and function members that are related to each other in the class. Which contains statements to perform a task.

When we are programming looking at OOPs, the code that is written to solve a problem is accessed from the object of that class.

More information about object is given in class and object

sending message in C ++

In this, objects communicate with each other by sending a message, when an object receives a message, the object calls its own function and executes the function of the class where it is declared.

Data encapsulation in C ++

Tying data member and function member together in a class is called data encapsulation-


As you can see that this is the syntax of a class, this means that we get data encapsulation features automatic as soon as the class is implemented.

Data abstraction in C ++

Data abstraction is implemented from data encapsulation itself. abstraction shows the end-user only the information he needs and the implementation hides.

for example –

To make a call from a mobile, we have to input the contact number but it does not show us how the mobile implemented this call.

Because a class provides a feature like abstraction, a class is also called abstract data type (ADT).

C ++ inheritance

This features codes for OOPs to facilitate re-usability. In this we add the properties or behavior of one class to another class. In this way, a class already has some of its own property and behavior but at the same time the property and behavior of another class also comes in it, without modifying any of the classes. More information about inheritance and its types is given.

Polymorphism in C ++

In Greek language. poly means – a lot and morphism means – types meaning the name is a work many.

Let us understand this with an example –

In the real world polytechnic represents many courses-

In similar oops, the external interface of any object or function is same but their property and behaviour (internal interface) are different from each other. property and behaviour means that they contain statements for different tasks. Examples


Like we have declared 3 function in a program and all the function-names are same but the number of parameters in each function is more or less or different types of parameters are declared. This will be called function overloading.

In C ++, polymorphism is divided into two parts-

Previous – storage specifiers in C++

Next – class and object in C++


Like it?

Leave a Reply

Your email address will not be published. Required fields are marked *

Exit mobile version