0% found this document useful (0 votes)
14 views

OOPs

Uploaded by

CyberPunk z
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

OOPs

Uploaded by

CyberPunk z
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

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.

Class is a user-defined data type, which holds its own data members and member functions, which can be
accessed and used by creating an instance of that class. 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 brand 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.

Encapsulation is defined as wrapping up of data and information under a single unit. 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”.

Abstraction means displaying only essential information and hiding the details. 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 accelerator the speed is actually increasing, he does not know about the inner mechanism of the car
or the implementation of accelerator, brakes etc in the car. This is what abstraction is.

• Abstraction using Classes: We can implement Abstraction in C++ using classes. The class helps us
to group data members and member functions using available access specifiers. A Class can decide
which data member will be visible to the outside world and which is not.
• Abstraction in Header files: One more type of abstraction in C++ can be header files. For example,
consider the pow() method present in math.h header file. Whenever we need to calculate the power
of a number, we simply call the function pow() present in the math.h header file and pass the
numbers as arguments without knowing the underlying algorithm according to which the function is
actually calculating the power of numbers.

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.

A person at the same time can have different characteristic. Like a man at the same time is a father, a
husband, an employee. So the same person posses different behaviour in different situations. This is called
polymorphism.

An operation may exhibit different behaviours in different instances. The behaviour depends upon the types
of data used in the operation.

C++ supports operator overloading and function overloading.

• Operator Overloading: The process of making an operator to exhibit different behaviours in different
instances is known as operator overloading.
• Function Overloading: Function overloading is using a single function name to perform different
types of tasks.
Polymorphism is extensively used in implementing inheritance.

The capability of a class to derive properties and characteristics from another class is called Inheritance.
Inheritance is one of the most important features of Object-Oriented Programming.

• Sub Class: The class that inherits properties from another class is called Sub class or Derived Class.
• Super Class:The class whose properties are inherited by sub class is called Base Class or Super
class.
• Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a new
class and there is already a class that includes some of the code that we want, we can derive our new
class from the existing class. By doing this, we are reusing the fields and methods of the existing
class.Example: Dog, Cat, Cow can be Derived Class of Animal Base Class.

You might also like