Introduction of Object Oriented Programming
Last Updated :
09 Feb, 2023
As the name suggests, Object-Oriented Programming or OOPs refers to languages that use objects in programming. Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc in programming. The main aim of OOP is to bind together the data and the functions that operate on them so that no other part of the code can access this data except that function.
OOPs Concepts:
- Class
- Objects
- Data Abstraction
- Encapsulation
- Inheritance
- Polymorphism
- Dynamic Binding
- Message Passing
1. Class:
A class is a user-defined data type. It consists of data members and member functions, which can be accessed and used by creating an instance of that class. It represents the set of properties or methods that are common to all objects of one type. A class is like a blueprint for an object.
For Example: Consider the Class of Cars. There may be many cars with different names and brands but all of them will share some common properties like all of them will have 4 wheels, Speed Limit, Mileage range, etc. So here, Car is the class, and wheels, speed limits, mileage are their properties.
2. Object:
It is a basic unit of Object-Oriented Programming and represents the real-life entities. An Object is an instance of a Class. When a class is defined, no memory is allocated but when it is instantiated (i.e. an object is created) memory is allocated. An object has an identity, state, and behavior. Each object contains data and code to manipulate the data. Objects can interact without having to know details of each otherâs data or code, it is sufficient to know the type of message accepted and type of response returned by the objects.
For example âDogâ is a real-life Object, which has some characteristics like color, Breed, Bark, Sleep, and Eats.

Object
3. Data Abstraction:
Data abstraction is one of the most essential and important features of object-oriented programming. Data abstraction refers to providing only essential information about the data to the outside world, hiding the background details or implementation. Consider a real-life example of a man driving a car. The man only knows that pressing the accelerators will increase the speed of the car or applying brakes will stop the car, but he does not know about how on pressing the accelerator the speed is increasing, he does not know about the inner mechanism of the car or the implementation of the accelerator, brakes, etc in the car. This is what abstraction is.
4. Encapsulation:
Encapsulation is defined as the wrapping up of data under a single unit. It is the mechanism that binds together code and the data it manipulates. In Encapsulation, the variables or data of a class are hidden from any other class and can be accessed only through any member function of their class in which they are declared. As in encapsulation, the data in a class is hidden from other classes, so it is also known as data-hiding.

Consider a real-life example of encapsulation, in a company, there are different sections like the accounts section, finance section, sales section, etc. The finance section handles all the financial transactions and keeps records of all the data related to finance. Similarly, the sales section handles all the sales-related activities and keeps records of all the sales. Now there may arise a situation when for some reason an official from the finance section needs all the data about sales in a particular month. In this case, he is not allowed to directly access the data of the sales section. He will first have to contact some other officer in the sales section and then request him to give the particular data. This is what encapsulation is. Here the data of the sales section and the employees that can manipulate them are wrapped under a single name âsales sectionâ.
5. Inheritance:
Inheritance is an important pillar of OOP(Object-Oriented Programming). The capability of a class to derive properties and characteristics from another class is called Inheritance. When we write a class, we inherit properties from other classes. So when we create a class, we do not need to write all the properties and functions again and again, as these can be inherited from another class that possesses it. Inheritance allows the user to reuse the code whenever possible and reduce its redundancy.

6. Polymorphism:
The word polymorphism means having many forms. In simple words, we can define polymorphism as the ability of a message to be displayed in more than one form. For example, A person at the same time can have different characteristics. Like a man at the same time is a father, a husband, an employee. So the same person posses different behavior in different situations. This is called polymorphism.

7. Dynamic Binding:
In dynamic binding, the code to be executed in response to the function call is decided at runtime. Dynamic binding means that the code associated with a given procedure call is not known until the time of the call at run time. Dynamic Method Binding One of the main advantages of inheritance is that some derived class D has all the members of its base class B. Once D is not hiding any of the public members of B, then an object of D can represent B in any context where a B could be used. This feature is known as subtype polymorphism.
8. Message Passing:
It is a form of communication used in object-oriented programming as well as parallel programming. Objects communicate with one another by sending and receiving information to each other. A message for an object is a request for execution of a procedure and therefore will invoke a function in the receiving object that generates the desired results. Message passing involves specifying the name of the object, the name of the function, and the information to be sent.
Why do we need object-oriented programming
- To make the development and maintenance of projects more effortless.
- To provide the feature of data hiding that is good for security concerns.
- We can solve real-world problems if we are using object-oriented programming.
- It ensures code reusability.
- It lets us write generic code: which will work with a range of data, so we don’t have to write basic stuff over and over again.
Similar Reads
Time until distance gets equal to X between two objects moving in opposite direction
Consider two people moving in opposite direction with speeds U meters/second and V meters/second respectively. The task is to find how long will take to make the distance between them X meters.Examples: Input: U = 3, V = 3, X = 3 Output: 0.5 After 0.5 seconds, policeman A will be at distance 1.5 met
4 min read
Calculate Work Done and Power Consumed by a particle
Given three integers F, D, and T representing the force acting on a particle, displacement traveled by the particle, and time consumed respectively, the task is to calculate Work done (W) and Power consumed (P) by that particle. Examples: Input: F = 100, D = 20, T = 100Output: Work done: 2000Power C
4 min read
Check if it is possible to create a polygon with a given angle
Given an angle [Tex]a [/Tex]where, [Tex]1\le a< 180 [/Tex]. The task is to check whether it is possible to make a regular polygon with all of its interior angle equal to [Tex]a [/Tex]. If possible then print "YES", otherwise print "NO" (without quotes). Examples: Input: angle = 90 Output: YES Pol
4 min read
10 Best C Programming Courses For Beginners [2025]
C is a foundational language that has influenced many subsequent languages, you must have a basic understanding of C in order to command any programming language. To enter the world of development, which is the most demanding and high-paying industry in todayâs world, getting complete knowledge of p
9 min read
Mth element after K Right Rotations of an Array
Given non-negative integers K, M, and an array arr[ ] consisting of N elements, the task is to find the Mth element of the array after K right rotations. Examples: Input: arr[] = {3, 4, 5, 23}, K = 2, M = 1 Output: 5 Explanation: The array after first right rotation a1[ ] = {23, 3, 4, 5} The array a
11 min read
Find all palindrome numbers of given digits
Given an integer D, the task is to find all the D-digit palindrome numbers.Examples: Input: D = 1 Output: 1 2 3 4 5 6 7 8 9Input: D = 2 Output: 11 22 33 44 55 66 77 88 99 Approach: Numbers with D-digits start from 10(D - 1) to 10D - 1. So, start checking every number from this interval whether it is
6 min read
What is the difference between single quoted and double quoted declaration of char array?
In C programming, the way we declare and initialize a char array can differ based on whether we want to use a sequence of characters and strings. They are basically same with difference only of a '\0' NULL character. Double quotes automatically include the null terminator, making the array a string
2 min read
Print squares of first n natural numbers without using *, / and -
Given a natural number 'n', print squares of first n natural numbers without using *, / and -. Examples : Input: n = 5Output: 0 1 4 9 16Input: n = 6Output: 0 1 4 9 16 25We strongly recommend to minimize the browser and try this yourself first.Method 1: The idea is to calculate next square using prev
8 min read
Count the pairs of vowels in the given string
Given a string str consisting of lowercase English alphabets, the task is to count the number of adjacent pairs of vowels.Examples: Input: str = "abaebio" Output: 2 (a, e) and (i, o) are the only valid pairs.Input: str = "aeoui" Output: 4 Approach: Starting from the first character of the string to
5 min read
Modify given array to a non-decreasing array by rotation
Given an array arr[] of size N (consisting of duplicates), the task is to check if the given array can be converted to a non-decreasing array by rotating it. If it's not possible to do so, then print "No". Otherwise, print "Yes". Examples: Input: arr[] = {3, 4, 5, 1, 2}Output: YesExplanation: After
10 min read
Deletion at end (Removal of last node) in a Linked List
Given a linked list, the task is to delete the last node of the given linked list. Examples:Â Â Input: 1 -> 2 -> 3 -> 4 -> 5 -> NULLOutput: 1 -> 2 -> 3 -> 4 -> NULL Explanation: The last node of the linked list is 5, so 5 is deleted. Input: 3 -> 12 -> 15-> NULLOutp
8 min read
Binary Search Tree In Python
A Binary search tree is a binary tree where the values of the left sub-tree are less than the root node and the values of the right sub-tree are greater than the value of the root node. In this article, we will discuss the binary search tree in Python. What is a Binary Search Tree(BST)?AÂ Binary Sear
12 min read
Maximize ropes of consecutive length possible by connecting given ropes
Given an array A[ ] of size N where each array element represents the length of a rope, the task is to find the number of ropes of consecutive length that can be created by connecting given ropes starting from length 1. Examples : Input: N = 5, A[ ] = {1, 2, 7, 1, 1} Output: 5 Explanation: Length |
6 min read
Program to find the Nth term of series -1, 2, 11, 26, 47......
Given a number N, the task is to find the Nth term of this series: -1, 2, 11, 26, 47, 74, ..... Examples: Input: 3 Output: 11 Explanation: when N = 3 Nth term = ( (3 * N * N) - (6 * N) + 2 ) = ( (3 * 3 * 3) - (6 * 3) + 2 ) = 11 Input: 9 Output: 191 Approach: The Nth term of the given series can be g
3 min read
Queries on sum of odd number digit sums of all the factors of a number
Given Q queries. Each query contain a positive integer n. The task is to output the sum of sum of odd number digit contained in all the divisors of n.Examples : Input : Q = 2, n1 = 10, n2 = 36 Output : 7 18 For Query1, Divisors of 10 are 1, 2, 5, 10. Sum of odd digits in 1 is 1, in 2 is 0, in 5 is 5
9 min read
Find largest prime factor of a number
Given a positive integer n ( 1 <= n <= 1015). Find the largest prime factor of a number. Input: 6Output: 3Explanation Prime factor are 2 and 3. Largest of them is 3.Input: 15Output: 5 The approach is simple, just factorize the given number by dividing it with the divisor of a number and keep u
9 min read
Permutations of n things taken all at a time with m things never come together
Given n and m, the task is to find the number of permutations of n distinct things taking them all at a time such that m particular things never come together.Examples: Input : 7, 3 Output : 420 Input : 9, 2 Output : 282240 Approach:Derivation of the formula - Total number of arrangements possible u
3 min read
Repdigit Numbers
Repdigit Number is a number N which has all the digits in its representation in base B equal.Some of the Repdigit number are: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44, 55.... Check if N is an Repdigit number Given a number N, the task is to check if N is an Repdigit Number in Base B or not. If N
5 min read
Count of all possible ways to reach a target by a Knight
Given two integers N, M denoting NÃM chessboard, the task is to count the number of ways a knight can reach (N, M) starting from (0, 0). Since the answer can be very large, print the answer modulo 109+7. Example: Input: N =3, M= 3Output: 2Explanation: Two ways to reach (3, 3) form (0, 0) are as foll
10 min read