Categories: C++

OOPs Concepts in C++

Object-oriented programming (OOPs) is a programming approach or pattern in which programs are structured around objects rather than functions and logic. It partitions the data into two memory areas, namely data and functions, and aids in making the code flexible and modular.

Concepts of an Object-Oriented Programming language:

There are some basic concepts that act as the building blocks of OOPs:

  • Classes & Objects
  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism
Class:

It is a user-defined data type with its own data members and member functions that can be accessed and used by instantiating the class. A class is similar to an object’s blueprint.

Object:

An Object is a distinguishable entity with certain characteristics and behavior. An Object is an instance of a Class. When a class is defined, no memory is allocated; however, memory is allocated when the class is instantiated (i.e. an object is created).

Encapsulation:

Encapsulation is defined as the consolidation of data and information into a single unit. Encapsulation is defined in Object-Oriented Programming as the binding of data and the functions that manipulate it.

Abstraction:

One of the most essential and important features of object-oriented programming in C++ is data abstraction. Abstraction entails displaying only the most important information while concealing the details. Data abstraction is the process of exposing only the essential information about a data set to the outside world while hiding the background details or implementation.

Polymorphism:

Polymorphism is defined as having multiple forms. Polymorphism is defined as the ability of a message to be displayed in more than one form. C++ supports operator overloading and function overloading.

Inheritance:

Inheritance refers to a class’s ability to derive properties and characteristics from another class. One of the most important aspects of Object-Oriented Programming is inheritance.

Benefits of OOPs:

Object-oriented programming has several advantages.

  • OOPs, allow code to be reused and extend the use of existing classes.
  • It is easier to maintain code in OOPs because there are classes and objects, which make it easier to maintain rather than restructure.
  • It also aids in data concealment, preventing data and information from leaking or being exposed.
  • Object-oriented programming is simple to use.

Real-world example: A class that represents a person is a simple example. The person class would have characteristics that represented data like the person’s age, name, height, and so on. The class description might also include functions like “SayMyName,” which prints that person’s name to the screen.

Note: also read about the Introduction to C++

Follow Me

If you like my post, please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Recent Posts

Square Root of Integer

Given an integer A. Compute and return the square root of A. If A is…

9 months ago

Build Array From Permutation

Given a zero-based permutation nums (0-indexed), build an array ans of the same length where…

9 months ago

DSA: Heap

A heap is a specialized tree-based data structure that satisfies the heap property. It is…

11 months ago

DSA: Trie

What is a Trie in DSA? A trie, often known as a prefix tree, is…

11 months ago

Trees: Lowest Common Ancestor

What is the Lowest Common Ancestor? In a tree, the lowest common ancestor (LCA) of…

11 months ago

Binary Search Tree (BST)

A Binary Search Tree (BST) is a type of binary tree that satisfies the following…

11 months ago