0% found this document useful (0 votes)
9 views4 pages

OOPS

OOPS notes for interview

Uploaded by

Rishi Sharma
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)
9 views4 pages

OOPS

OOPS notes for interview

Uploaded by

Rishi Sharma
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/ 4

Difference Between Procedure Oriented Programming (POP) & Object

Oriented Programming (OOP)


Procedure Oriented Programming Object Oriented Programming
Importance is not given to data but to Importance is given to the data rather than
functions as well as sequence of actions to be procedures or functions because it works as a
done real world.
follows Top Down approach. OOP follows Bottom Up approach.
It does not have any access specifier OOP has access specifiers named Public, Private,
Protected, etc.
Data can move freely from function to function in objects can move and communicate with each
the system other through member functions.
Overloading is not possible In OOP, overloading is possible in the form of 9
Overloading is not possible. Function Overloading
and Operator Overloading

what does it mean when we say that in c++ more emphasis is


given on data rather than procedure

In both procedural programming (using structures in C) and object-oriented programming (using


classes in C++), you can control which functions have access to certain data. This is often done
by organizing your code in such a way that only certain functions have access to the data they
need to operate on.
However, the key difference lies in how this is enforced:
 In C++ (Object-Oriented Programming): The language itself provides features like classes and
access modifiers (private, protected, public) to enforce data encapsulation at the language level.
This means you can make certain data members private, and they can only be accessed or
modified by member functions within the same class.
 In C (Procedural Programming): While you can design your code in such a way that only
certain functions have access to specific structure data, the C language itself does not provide a
built-in way to enforce this. There are no access modifiers like private or public. Any function
that has a pointer to a structure can access and modify all members of the structure.
So, while in practice you can control access to data in both paradigms, the level of enforcement
by the language itself is stronger in object-oriented programming languages like C++. This is one
of the reasons why object-oriented programming can be more suitable for larger, more complex
applications where data integrity and security are important.
What does it mean when we says that procedural oriented
programming follows top-down approach while object oriented
programming follows bottom-up approach
The terms “top-down” and “bottom-up” are more about the approach to designing and
implementing the solution, rather than the problem itself:
 Top-Down (Procedural Programming): You start with the main problem and break it
down into smaller, manageable sub-problems or procedures. These procedures are
often written as separate functions which are then called by the main function. The focus
is on the sequence of actions to be performed (the procedures).
 Bottom-Up (Object-Oriented Programming): You start by identifying the objects (the
“bottom”) involved in the problem, define their properties and behaviors, and then
combine these objects to create the overall system (the “top”). The focus is on the data
(objects) and operations that can be performed on them (methods).

In the rectangle area example, the problem is the same in both cases - calculate the area
of a rectangle. But the approach to solving the problem is different:
 In the procedural version, we start with the main problem (calculate area), and break it
down into a smaller problem (multiply length and width), which is solved with a
function.
 In the object-oriented version, we start by defining the objects involved (a Rectangle),
specify its properties (length and width) and behaviors (calculate area), and then use an
instance of this object to solve the problem

Principles( or features) of object oriented programming:

1. Encapsulation

2. Data abstraction

3. Polymorphism

4. Inheritance

5. Dynamic binding

6. Message passing

Encapsulation: Wrapping of data and functions together as a single unit is known as encapsulation. By
default data is not accessible to outside world and they are only accessible through the functions which
are wrapped in a class. prevention of data direct access by the program is called data hiding or
information hiding

Data abstraction : Abstraction refers to the act of representing essential features without including the
back ground details or explanation. Classes use the concept of abstraction and are defined as a list of
attributes such as size, weight, cost and functions to operate on these attributes. They encapsulate all
essential properties of the object that are to be created. The attributes are called as data members as
they hold data and the functions which operate on these data are called as member functions. Class use
the concept of data abstraction so they are called abstract data type (ADT)

Polymorphism: Polymorphism comes from the Greek words “poly” and “morphism”. “poly” means many
and “morphism” means form i.e.. many forms. Polymorphism means the ability to take more than one
form. For example, an operation have different behavior in different instances. The behavior depends
upon the type of the data used in the operation. Different ways to achieving polymorphism in C++
program:

1) Function overloading

2) Operator overloading

#include

using namespace std;

int main()

int a=4;

a=a<<2;

cout<<a<<endl;

return 0;

Inheritance: Inheritance is the process by which one object can acquire the properties of another.
Inheritance is the most promising concept of OOP, which helps realize the goal of constructing software
from reusable parts, rather than hand coding every system from scratch. Inheritance not only supports
reuse across systems, but also directly facilitates extensibility within a system. Inheritance coupled with
polymorphism and dynamic binding minimizes the amount of existing code to be modified while
enhancing a system.

When the class child, inherits the class parent, the class child is referred to as derived class (sub class)
and the class parent as a base class (super class). In this case, the class child has two parts: a derived part
and an incremental part. The derived part is inherited from the class parent. The incremental part is the
new code written specifically for the class child.

Dynamic binding: Binding refers to linking of procedure call to the code to be executed in response to
the call. Dynamic binding(or late binding) means the code associated with a given procedure call in not
known until the time of call at run time.

Message passing: An object oriented program consists of set of object that communicate with each
other. Objects communicates with each other by sending and receiving information . A message for an
object is a request for execution of a procedure and there fore invoke the function that is called for an
object and generates result

You might also like