OBJECT-ORIENTED PROGRAMMING IN C++

In this article, we are going to learn about Data Abstraction, Polymorphism, and Inheritance.

Data abstraction:

Data abstraction refers to providing only essential information and hiding all other unnecessary data. In C++, classes provide a great level of abstraction. They provide sufficient public methods to play with the functionality of the object and to manipulate object data.

Let’s look at a sample program implementing data abstraction.

The output of the program is.

In the above example, we add the numbers and return their sum. There are some of the interfaces that a user needs to know to use a class.

Polymorphism:

The term “ polymorphism ” means many forms. It means the same entity can be able to display in many forms.

For example, there is a man. He works as an employee in the office, as a father for his children and as a son for his parents. Here the same man possesses different names in different scenarios. This is known as polymorphism.

The polymorphism is of two types.

  1. Compile time polymorphism
  2. Runtime polymorphism

Compile time polymorphism:

 The overloaded functions are invoked by matching the type and number of arguments. This information is available at the compile time. therefore, the compiler selects the appropriate function at the compile time. It is achieved by function overloading and operator overloading which is also known as static binding or early binding.

Runtime polymorphism:

Run time polymorphism is achieved when the object’s method is invoked at the run time instead of compile time. It is achieved by method overriding which is also known as dynamic binding or late binding.

See also  C++ STRING FUNCTIONS:

Inheritance:

Inheritance is the most important feature of object-oriented programming which deals with acquiring properties from the parent class to the derived class. Here, the class from which the properties are acquired is called as the super/parent class and the class which acquires the properties is called the child/derived class.

Inheritance allows us to reuse the code. Like, if we want to create a new class with some of the properties that are already existed in some other class, we can derive those properties from the existed class to the derived class by using inheritance.

Let’s look at a sample program implementing the inheritance concept.

The output of the program is.

Here, in the above program, the class child is acquiring the public variables of the class parent through inheritance and accessing them. So, the demonstration of inheritance in C++ is done by the above method.

CONCLUSION

So, that’s it from this tutorial. Hope you find it useful. We learned about object-oriented programming and its concepts in C++. happy coding!

Leave a Comment

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

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

we provide projects, courses, and other stuff for free. in order for running we use Google ads to make revenue. please disable adblocker to support us.