You are on page 1of 4

Chapter

#
Nine
Basis of Object Oriented Programming (OOPs)
Introduction to OOPs
The prime purpose of C++ programming was to add object orientation to
the C programming language, which is in itself one of the most powerful
programming languages.
The core of the pure object-oriented programming is to create an object, in
code, that has certain properties and methods.
While designing C++ modules, we try to see whole world in the form of
objects. For example a car is an object which has certain properties such as
color, number of doors, and the like. It also has certain methods such as
accelerate, brake, and so on.
There are few principle concepts which are the foundation of objectoriented programming.
1) Object.
2) Class.
3) Abstraction.
4) Encapsulation.
5) Inheritance.
6) Polymorphism.
7) Overloading.
1) Object This is the basic unit of object oriented programming. When a program is
executed, objects interact with each other by sending messages. Different
objects can also interact with each other without knowing the details of their
data or code.
Each copy of an object
from a particular class is
called an instance of the
object.
2) Class A class is a collection of objects of similar type. Once a class is defined, any
number of objects can be created which belong to that class.

For Example:- India----Uttar Pradesh----Agra

3)

Class
Sub-Class Derived Class
AbstractionAbstraction is the act of representing essential features without including the
background details or explanations. Or to provide only essential information
to the outside word and hiding their background details.
Data cannot be accessible to the outside world and only those functions
which are stored in the class can access it.
For example, a database system hides certain details of how data is stored
and created and maintained. Similar way, C++ classes provides different
methods to the outside world without giving internal detail about those
methods and data.

4) Encapsulation Storing data and functions in a single unit (class) is encapsulation.


This world is taken from the world capsule. In which essential medicine is
covered within the cover.
Encapsulation is the concept of securing a program with another program.
5) Inheritance Inheritance is the process by which objects can acquire the properties of
objects of other class. In OOP, inheritance provides reusability, like, adding
additional features to an existing class without modifying it. This is achieved
by deriving a new class from the existing one. The new class will have
combined features of both the classes.
One of the most useful aspects of object-oriented programming is code
reusability.
As the name suggests Inheritance is the process of forming a new class from
an existing, new class is formed called as derived class.
This is a very important
concept of object oriented
programming since this
feature helps to reduce the
code size.
6) Polymorphism-

Polymorphism means the ability to take more than one form. An operation
may exhibit different behaviors in different instances.
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 many. That is a single function or an operator
functioning in many ways different upon the usage is called polymorphism.
7) 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 b/w c & c++


C files are stored with an extension '.c' whereas C++ files are stored with
'.cpp'.
C is a low level language and is less user friendly where as C++ is a middle
level language and is more user friendly too.
The execution in C is from top to down where as that in C++ is from bottom
to up.
We cannot do overloading with C where as C++ supports both function and
operator overloading.
C is Procedure Oriented Programming Language (POP) and C++ is Object
Oriented Programming Language (OOP).
C is mostly used to develop system software and C++ is mostly used to
modal real life problem to program and use to develop application programs.
In case of C, the data is not secured while the data is secured in C++.This
difference is due to specific OOP feature like Data Hiding which are not
present in C.
C is function-driven while C++ is object-driven.
We can use functions inside structures in C++ but not in C.
C++ uses NAMESPACE which avoid name collisions. For instance, two
students enrolled in the same university cannot have the same roll number
while two students in different universities might have the same roll number.
The universities are two different namespace & hence contain the same roll
number but the same university cannot have two students with the same roll
number.

The standard input & output functions differ in the two languages.C uses
scanf & printf while C++ uses cin>> & cout<< as their respective input &
output functions.
C++ allows the use of reference variables while C does not. Reference
variables allow two variable names to point to the same memory location.
We cannot use these variables in C programming.

MORE
C++ supports Exception Handling while C does not.C does not support it
formally but it can always be implemented by other methods.

You might also like