0% found this document useful (0 votes)
15 views11 pages

OOP Concepts in C++ (08-01-2021)

C++ supports object-oriented programming features like classes, objects, encapsulation, inheritance, and polymorphism that are not present in C. It was developed in 1979 by Bjarne Stroustrup at Bell Labs as an enhancement to the C language with object-oriented capabilities. Some key differences between C and C++ are that C++ supports concepts like data encapsulation, inheritance, and polymorphism which allow it to use an object-oriented approach to programming.

Uploaded by

mohitnajkani786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views11 pages

OOP Concepts in C++ (08-01-2021)

C++ supports object-oriented programming features like classes, objects, encapsulation, inheritance, and polymorphism that are not present in C. It was developed in 1979 by Bjarne Stroustrup at Bell Labs as an enhancement to the C language with object-oriented capabilities. Some key differences between C and C++ are that C++ supports concepts like data encapsulation, inheritance, and polymorphism which allow it to use an object-oriented approach to programming.

Uploaded by

mohitnajkani786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Object Oriented Programming in C++

Differences between C and C++ are:

C C++

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

Programming Platform
For the development of code, C++ is known as hybrid
C supports procedural language because C++ supports
programming. 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 does not support C++ supports polymorphism,


polymorphism, encapsulation, encapsulation, and inheritance
and inheritance which mean because it is an object
that C does not support object oriented programming

Thursday, 07 March 2024 Page:-1


Object Oriented Programming in C++

language.
oriented programming.

Data and functions


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

Information Hiding
C does not support information
Data is hidden by the
hiding.
Encapsulation to ensure that
data structures and operators
are used as intended.

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


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

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

Functions Inside Structure


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

Thursday, 07 March 2024 Page:-2


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

Virtual Function
Virtual functions, Pure Virtual Virtual functions, Pure Virtual
functions are not supported by functions are supported by C+
C. +.

Friend Function
friend functions and Friend friend functions and Friend
Class are not supported by C. Classes are supported by C++.

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

Data Handling
C++ focuses on data instead of
Instead of focusing on data, C
focusing on method or
focuses on method or process.
procedure.

Memory Allocation
C provides malloc() and calloc() C++ provides new operator for
functions for dynamic memory memory allocation and delete
allocation, and free() for operator for memory de-
memory de-allocation. allocation.

Thursday, 07 March 2024 Page:-3


Object Oriented Programming in C++

Exception Handling
Exception handling is
Direct support for exception
supported by C++.
handling is not supported by C.

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

Programming Approach
object oriented programming
Structure/procedure oriented
languages like C++
programming languages like C
programming language follows
programming language follows
bottom up approach.
top down approach.

Scope Resolution Operator


C does not support the scope
resolution operator.

Scope resolution operator is


used to access the global
variables and define methods
outside the class.
C++ supports scope resolution
operator as it uses it to
access global variables. It also

Thursday, 07 March 2024 Page:-4


Object Oriented Programming in C++

allows us to define functions


outside the class and access
them using the scope
resolution operator.

In C++ objects are managed


manually. The creation and
destruction of objects are
Object Management carried out manually using the
C does not support object and new and delete operators
object oriented programming respectively. We also use
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.

Thursday, 07 March 2024 Page:-5


Object Oriented Programming in C++

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.
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.

Thursday, 07 March 2024 Page:-6


Object Oriented Programming in C++

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.

Thursday, 07 March 2024 Page:-7


Object Oriented Programming in C++

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.
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.

Thursday, 07 March 2024 Page:-8


Object Oriented Programming in C++

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.
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.

Thursday, 07 March 2024 Page:-9


Object Oriented Programming in C++

Advantages of OOP over Procedure-oriented programming


language :
Data Representation in Procedure-Oriented Programming is :

Data Representation in Object-Oriented Programming is :

#1) Reusability
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.

Thursday, 07 March 2024 Page:-10


Object Oriented Programming in C++

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.

Thursday, 07 March 2024 Page:-11

You might also like