OOP_Concepts_in_C++(08-01-2021)
OOP_Concepts_in_C++(08-01-2021)
C C++
Development
C was developed by Dennis
C++ was developed by
Ritchie between the year
Bjarne Stroustrup in 1979.
1969 and 1973 at AT&T Bell
Labs.
Programming Platform
For the development of C++ is known as hybrid
code, C supports procedural language because C++
programming. supports both procedural
and object oriented
programming paradigms.
Keywords
C contains 32 keywords. C++ contains 52 keywords.
Programming Features
C++ supports
C does not support
polymorphism,
polymorphism,
encapsulation, and
encapsulation, and
inheritance because it is an
inheritance which mean that
object oriented
C does not support object
programming language.
oriented programming.
Information Hiding
C does not support Data is hidden by the
information hiding. Encapsulation to ensure that
data structures and
operators are used as
intended.
Overloading
Function and operator Function and operator
overloading is not supported overloading is supported by
in C. C++.
Reference variable
Reference variables are not Reference variables are
supported by C. supported by C++.
Virtual Function
Virtual functions, Pure Virtual functions, Pure
Virtual functions are not Virtual functions are
supported by C. supported by C++.
Friend Function
friend functions and Friend friend functions and Friend
Class are not supported by Classes are supported by
C. C++.
Inheritance
C does not support
C++ supports inheritance.
inheritance.
Data Handling
Instead of focusing on data, C++ focuses on data
C focuses on method or instead of focusing on
process. method or procedure.
Memory Allocation
C provides malloc() and
C++ provides new operator
calloc() functions for
for memory allocation and
dynamic memory allocation,
delete operator for memory
and free() for memory de-
de-allocation.
allocation.
Exception Handling
Direct support for exception Exception handling is
handling is not supported by supported by C++.
C.
Input/Output
scanf() and printf() functions
cin and cout are used for
are used for input/output in
input/output in C++.
C.
Programming Approach
object oriented
Structure/procedure
programming languages like
oriented programming
C++ programming
languages like C
language follows bottom up
programming language
approach.
follows top down approach.
Class:
1. The building block of C++ that leads to Object-Oriented
programming is a Class.
Object:
1. An Object is an identifiable entity with some characteristics
and behaviour.
2. An Object is an instance of a Class.
3. When a class is defined, no memory is allocated but when it
is instantiated (i.e. an object is created) memory is allocated.
4. Each object contains data and code to manipulate the data.
5. The central theme of a class: data members are hidden in
the private section, and can only be changed by the public
member functions.
Encapsulation:
1. Encapsulation is placing the data and the functions (that
work on that data) in the same place.
2. Object-oriented programming provides us a framework to
place the data and the relevant functions together in the
same object.
3. By doing this, data is not easily accessible to the outside
world.
4. In OOP we achieve encapsulation by making data members
as private and having public functions to access these data
members.
5. As in encapsulation, the data in a class is hidden from other
classes, so it is also known as data-hiding.
Abstraction:
1. Abstraction is the process of hiding irrelevant information
from the user.
2. For Example, when we are driving the car, first we start the
engine by inserting a key. We are not aware of the process
that goes on in the background for starting the engine.
3. By using abstraction in our application, the end user is not
affected even if we change the internal implementation.
4. For example, a database system hides certain details of how
data is stored and created and maintained.
5. Data Abstraction may also be defined as the process of
identifying only the required characteristics of an object
ignoring the irrelevant details.
6. Similar way, C++ classes provides different methods to the
outside world without giving internal detail about those
methods and data.
● 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 details of the function.
Polymorphism:
1. 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.
2. Poly refers to many.
Inheritance:
1.Inheritance is the process of forming a new class from an
existing class, here existing class is called as base class,
new class is formed called as derived class.
2. Inheritance provides reusability of code.
3. The derived class is the specialized class for the base
class.
1.Sub Class:=The class that inherits properties from
another class is called Sub class or Derived Class.
2.Super Class: =The class whose properties are
inherited by sub class is called Base Class or Super
class.
Message Passing:=
1.Objects communicate with one another by sending and
receiving information to each other.
#1) Reusability