Practical Explanation : Can anyone Explain the dif

2019-06-11 23:01发布

I visited so many sites about the differences between Procedular Oriented Programming and Object Oriented Programming , but I did not get Practical answer .

Everyone is saying theoritical answer .

Can anyone give Practical Explanation for this ?

1条回答
2楼-- · 2019-06-11 23:36

Procedural programming is a list or set of instructions telling a computer what to do step by step and how to perform from the first code to the second code.

the best example of a procedural language is C

for e.g here is a python code for procedural programming (any code without oops):

x = int(input('enter a number: '))

def even_odd(x):
    if x%2 == 0:
        print('even')
    else:
        print('odd')

even_odd(x)

Object oriented programming is the style of programming which uses classes and objects to wrap your code and data which helps to use lesser code and at only one place.

every modern language uses oop

for e.g:

class test:
    # your code here along with variables and functions
    x = 'something' #some code
    def test_func(): # some function 
        #your function code here

obj = test()  #this is the object created for the above class which will be used to access the data inside a class

theoretically, as a real world example I think that even god also uses object oriented programming, maybe he first created a parent class called living things which contains exact same properties like exact 2 eyes, 2 hands, one mouth etc, and then he inherited more subclasses like human being, tiger, rat from the same parent class ;)

查看更多
登录 后发表回答