0% found this document useful (0 votes)
6 views10 pages

OOP_Concepts_in_C++(08-01-2021)

Uploaded by

mohitnajkani786
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
6 views10 pages

OOP_Concepts_in_C++(08-01-2021)

Uploaded by

mohitnajkani786
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 10

Object Oriented Programming in C++

Differences between C and C++ are:

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.

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

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.

Saturday, 14 December 2024 Page:-1


Object Oriented Programming in C++

Data and functions


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

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.

C is a function driven C++ is an object driven


language because C is a language because it is an
procedural programming object oriented
language. programming.

Overloading
Function and operator Function and operator
overloading is not supported overloading is supported by
in C. C++.

Functions Inside Structure


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

Header file used by C is Header file used by C++ is


stdio.h. iostream.h.

Reference variable
Reference variables are not Reference variables are
supported by C. supported by C++.

Saturday, 14 December 2024 Page:-2


Object Oriented Programming in 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.

Saturday, 14 December 2024 Page:-3


Object Oriented Programming in 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.

Scope resolution operator is


used to access the global
Scope Resolution Operator variables and define
C does not support the methods outside the class.
scope resolution operator. C++ supports scope
resolution operator as it
uses it to access global
variables. It also allows us to
define functions outside the
class and access them using
the scope resolution
operator.

In C++ objects are


managed manually. The
Object Management
creation and destruction of
C does not support object
objects are carried out
and object oriented
manually using the new and
programming
delete operators
respectively. We also use

Saturday, 14 December 2024 Page:-4


Object Oriented Programming in C++

constructors and destructors


for class objects.

Object Oriented Programming Concepts in C++

1. Object-Oriented Programming or OOPs refers to languages


that use objects in programming.
2. Object-oriented programming aims to implement real-world
entities like inheritance, polymorphism etc in programming.
3. 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.
4. It Emphasis is on data rather than procedure.
5. Data is hidden and cannot be accessed by external
functions.

Some Basic Characteristics of Object Oriented Programming:-


1. Class
2. Objects
3. Encapsulation
4. Abstraction
5. Polymorphism
6. Inheritance
7. Message Passing

Class:
1. The building block of C++ that leads to Object-Oriented
programming is a Class.

Saturday, 14 December 2024 Page:-5


Object Oriented Programming in C++

2. A 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.
3. Together these data members and member functions define
the properties and behaviour of the objects in a Class.
4. A class is like a blueprint for an object.

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.

Saturday, 14 December 2024 Page:-6


Object Oriented Programming in C++

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.

Saturday, 14 December 2024 Page:-7


Object Oriented Programming in C++

3. Eg:-A person at the same time can have different


characteristic. Like a man at the same time is a father, a
husband, an employee.
4. So the same person posses different behaviour in different
situations. This is called polymorphism.
5. Types of Polymorphism
a. Compile Time(Operator Overloading, Function
Overloading)
b. Run Time(Virtual Function)

Late binding or Dynamic linkage


1. In late binding function call is resolved during runtime.
2. In dynamic binding, the code to be executed in response to
function call is decided at runtime.
3. C++ has virtual function to support this.

Early Binding(Compile time)


1. It is done according to the type of pointer.
2. C++ supports operator overloading and function overloading to
implement compile time polymorphism.

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.

Saturday, 14 December 2024 Page:-8


Object Oriented Programming in C++

2.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.
3.Message passing involves specifying the name of the object,
the name of the function and the information to be sent.

Advantages of OOP over Procedure-oriented


programming language :
Data Representation in Procedure-Oriented Programming
is :

Data Representation in Object-Oriented Programming is :

#1) Reusability

Saturday, 14 December 2024 Page:-9


Object Oriented Programming in C++

1.OOP allows the existing code to be reused through


inheritance.
#2) Modularity
1. As we modularize the program in OOP, it’s easy to
modify the program if a problem occurs or new feature or
enhancement is to be added.
#3) Flexibility
1.OOP helps us with flexible programming using the
polymorphism feature.
2.As polymorphism takes many forms, we can have operators
or functions that will work with many objects and thus save
us from writing different functions for each object.
#4) Maintainability
1.Maintaining code is easier as it is easy to add new classes,
objects, etc without much restructuring or changes.
#5) Data and Information Hiding
1.OOP aids us in data hiding thereby keeping information safe
from leaking.

Saturday, 14 December 2024 Page:-10

You might also like