Competitive Exams
Computer Science
Computer Science Class 10
Olympiad Preparation - Class 1 - 10
OOPs Interview Questions
Uncategorized
Unified Cyber Olympiad Preparation
Difference between Procedural and Object Oriented Programming
Procedural Oriented Programming | Object Oriented Programming |
---|---|
In procedural programming, program is divided into small parts called functions. Example code : #include <stdio.h> /*this function computes the absolute value of a whole number.*/ int abs(int x) { if (x>=0) return x; else return -x; } /*this program calls the abs() function defined above twice.*/ int main() { int x, printf(” x=”); scanf(“%d”, &x); printf(“Absolute Value of x is %d. \n”, abs(x)); return 0; } | In object oriented programming, program is divided into small parts called objects. Example code : class Parrot: # class attribute species = "bird" # instance attribute def __init__(self, name, age): self.name = name self.age = age instantiate the Parrot class blu = Parrot(“Blu”, 10) woo = Parrot(“Woo”, 15) access the class attributes print(“Blu is a {}”.format(blu.class.species)) print(“Woo is also a {}”.format(woo.class.species)) access the instance attributes print(“{} is {} years old”.format( blu.name, blu.age)) print(“{} is {} years old”.format( woo.name, woo.age)) |
Procedural programming follows top down approach. Note: A top-down approach is essentially the breaking down of a program to gain insight into its compositional small program (or module) in a reverse engineering fashion. | Object oriented programming follows bottom up approach. Note : A bottom-up approach is the piecing together of module (or small program) to give rise to more complex program, thus making the original modules of the emergent program. |
There is no access specifier in procedural programming. | Object oriented programming have access specifiers like private, public, protected etc. |
Adding new data and function is not easy. | Adding new data and function is easy. |
Procedural programming does not have any proper way for hiding data so it is less secure. | Object oriented programming provides data hiding so it is more secure. |
In procedural programming, overloading is not possible. | Overloading is possible in object oriented programming. Overloading methods lets you define the same method multiple times so that you can call them with different argument lists (a method’s argument list is called its signature) |
In procedural programming, function is more important than data. | In object oriented programming, data is more important than function. |
Procedural programming is based on unreal world. | Object oriented programming is based on real world. |
Data can move freely from procedure to procedure in the system | Objects can move and communicate with each other through member functions |
Examples: C, FORTRAN, Pascal, Basic etc. | Examples: C++, Java, Python, C# etc. |