OOPs (Object Oriented Programming)

OOPs (Object Oriented Programming):

- Python is an object-oriented programming language.

- OOPs used in application development.

- In Python, we can easily create and use classes and objects.


Concepts of OOPs:

1. Object:

- Object is an entity that has a state and behaviour.

- State means property of an Object.

- Behaviour means function/method of an Object.

- Example: pen, pencil, table, phone, keyboard etc.


                    PHONE

                      ↙              ↘

State (Properties)                   Behaviour (Functions)       

    Color                                                   Make Calls

    Cost                                                    Watch Videos

  Battery life                                             Play Games


2. Class:

- Class is the collection of similar types of objects.

- Example: An Animal class that has the dog, cat, and cow objects.


3. Method

- Method which is also called function, is related to the object.

- All objects have their methods/functions.

- Example: list objects have methods like append, sort, remove, insert etc.


4. Inheritance

- Inheritance is the feature of object-oriented programming.

- In inheritance, the child class acquires all the properties and functions of the parent class.

- The new class is known as the derived class or child class which inherits the properties and functions from the base class or parent class.


5. Polymorphism

- Polymorphism is a concept.

- Ability to take various forms called Polymorphism.

- Example: If we run print(5+6) code, we will get 11.

- If we run print(“5”+”6”) code, 5 and 6 in the string then 
we will get 56.

- In the above examples, the difference between outputs is called polymorphism it takes the various roles in integer and string forms.


6. Data Abstraction

- Data abstraction is a process of hiding unnecessary information from the user.

- Example: An application’s internal implementation is hiding from the user, the user can only use the application.


7. Encapsulation

- Encapsulation is also a feature of object-oriented programming.

- Encapsulation is the concept of bundling the data and method into a single unit.

- Example: A class that encapsulates all the data that is 
variables and methods into a single unit.

Comments