(Ref : https://www.analyticsvidhya.com/blog/2020/09/object-oriented-programming/ Accessed on 21st June 2022) . This is a practise project for documentation and texts here are borrowed from the above references.
- :ref:`Class`
- :ref:`Object`
- :ref:`Method`
- :ref:`Inheritance`
- :ref:`Encapsulation`
- :ref:`Polymorphism`
- :ref:`Data abstraction`
Classes are user defined data structures (contrast with primitive data types-Integers,Float,Strings,Boolean) . It is also blueprint for creating many objects each with custom values. Let's begin with creating a car class without any details :
class Car:
pass
Now let's add name , color as we expect real world Sedan car to have one through class constructor _init_ :
class Car:
car_type = "Sedan" #class attribute - common to all objects.
def __init__(self, name, color):
self.name = name #instance attribute -each instance may have different value.
self.color = color #instance attribute -each instance may have different value.
Creating a particular instance for a red Honda City.
obj1 = Car("Honda City","Red")
Creating another instance for a blue Maruti Dzire.
obj2 = Car("Maruti Dzire","Blue")
.. toctree:: :maxdepth: 2 :caption: Contents: