What Is Object-Oriented Programming (OOP) ?

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

What is object-oriented programming (OOP)?

Object-oriented programming (OOP) is a programming paradigm based on the concept of


"objects", which may contain data, in the form of fields, often known as attributes; and
code, in the form of procedures, often known as methods. For example, a person is an
object which has certain properties such as height, gender, age, etc. It also has certain
methods such as move, talk, and so on.
Object
This is the basic unit of object-oriented programming. That is both data and function that
operate on data are bundled as a unit called an object.
Class
When you define a class, you define a blueprint for an object. This doesn't actually define
any data, but it does define what the class name means, that is, what an object of the class
will consist of and what operations can be performed on such an object.
OOP has four basic concepts on which it is totally based. Let's have a look at them
individually −
 Abstraction − It refers to, providing only essential information to the outside world and
hiding their background details. For example, a web server hides how it processes data it
receives, the end user just hits the endpoints and gets the data back.
 Encapsulation − Encapsulation is a process of binding data members (variables, properties)
and member functions (methods) into a single unit. It is also a way of restricting access to
certain properties or component. The best example for encapsulation is a class.
 Inheritance − The ability to create a new class from an existing class is called Inheritance.
Using inheritance, we can create a Child class from a Parent class such that it inherits the
properties and methods of the parent class and can have its own additional properties and
methods. For example, if we have a class Vehicle that has properties like Color, Price, etc,
we can create 2 classes like Bike and Car from it that have those 2 properties and additional
properties that are specialized for them like a car has numberOfWindows while a bike
cannot. Same is applicable to methods.
Polymorphism − The word polymorphism means having many forms. Typically,
polymorphism occurs when there is a hierarchy of classes and they are related by
inheritance. C++ polymorphism means that a call to a member function will cause a different
function to be executed depending on the type of object that invokes the function.
The ability to use an operator or function in different ways in other words giving different
meaning or functions to the operators or functions is called polymorphism. Poly refers to
many. That is a single function or an operator functioning in many ways different upon the
usage is called polymorphism.
Overloading
The concept of overloading is also a branch of polymorphism. When the exiting operator or
function is made to operate on new data type, it is said to be overloaded.
DIFFERENCE BETWEEN C AND C++

C C++

C was developed by Dennis Ritchie


between the year 1969 and 1973 at AT&T C++ was developed by Bjarne Stroustrup in
Bell Labs. 1979.

C does no support polymorphism, C++


encapsulation, and inheritance which supports polymorphism, encapsulation,
means that C does not support object and inheritance because it is an object
oriented programming. oriented programming language.

C is a subset of C++. C++ is a superset of C.

C contains 32 keywords. C++ contains 63 keywords.

C++ is known as hybrid language because


For the development of code, C C++ supports both procedural and object
supports procedural programming. oriented programming paradigms.

Data and functions are separated in C


because it is a procedural programming Data and functions are encapsulated
language. together in form of an object in C++.

Data is hidden by the Encapsulation to


ensure that data structures and operators
C does not support information hiding. are used as intended.

Built-in & user-defined data types is


Built-in data types is supported in C. supported in C++.

C is a function driven language because C C++ is an object driven language because it


is a procedural programming language. is an object oriented programming.
C C++

Function and operator overloading is not Function and operator overloading is


supported in C. supported by C++.

C is a function-driven language. C++ is an object-driven language

Functions in C are not defined inside Functions can be used inside a structure in
structures. C++.

Namespace features are not present Namespace is used by C++, which avoid
inside the C. name collisions.

Header file used by C is stdio.h. Header file used by C++ is iostream.h.

Reference variables are not supported by


C. Reference variables are supported by C++.

Virtual and friend functions are not Virtual and friend functions are supported


supported by C. by C++.

C does not support inheritance. C++ supports inheritance.

Instead of focusing on data, C focuses on C++ focuses on data instead of focusing on


method or process. method or procedure.

C provides malloc() and calloc() functions C++ provides new operator for memory


for dynamic memory allocation, allocation and delete operator for memory
and free() for memory de-allocation. de-allocation.

Direct support for exception handling is


not supported by C. Exception handling is supported by C++.
C C++

scanf() and printf() functions are used for cin and cout are used for input/output in
input/output in C. C++.

C structures don’t have access modifiers. C ++ structures have access modifiers.

C follows the top-down approach C++ follows the Bottom-up approach

Strict type checking in done in C++.  So


many programs that run well in C compiler
There is no strict type checking in C will result in many warnings and errors
programming language. under C++ compiler.

C does not support overloading C++ does support overloading

You might also like