OOPs in a nutshell...
Tags: python, beginners, programming
Published: 2022-10-13 10:30:40

<strong>Object-Oriented Programming</strong> is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance by providing some concepts defined below:<br>

<strong>Class</strong> is a user-defined data type which defines its properties and its functions. Class is the only logical representation of the data. For example, Human being is a class. The body parts of a human being are its properties, and the actions performed by the body parts are known as functions. The class does not occupy any memory space till the time an object is instantiated.

<h2>Syntax for C++ (CLASS)</h2>
<pre>
  class student{
      public:
             int id;
             int phone;
             string place;
             int add(int x, int y){
             return x + y;
     }
  };
</pre>

<strong>Object</strong> is a run-time entity. It is an instance of the class. An object can represent a person, place or any other item. An object can operate on both data members and member functions.
<h2>Syntax for C++ (OBJECTS)</h2>
<pre>carModel l = new car(); </pre>

<h2>Encapsulation</h2>
<strong>Encapsulation</strong> is the process of combining data and functions into a single unit called class. In Encapsulation, the data is not accessed directly, it is accessed through the functions present inside the class. In simpler words, attributes of the class are kept private and public getter and setter methods are provided to manipulate these attributes.

<h2>Polymorphism</h2>
<strong>Polymorphism</strong> is the ability to present the same interface for differing underlying forms. With polymorphism, each of these classes will have different underlying data. Precisely, Poly means ‘many’ and morphism means ‘forms’.

<strong><u>Types</u> <u>of</u> <u>Polymorphism</u> :</strong>
<ol type="A">
<em><li>Compile Time Polymorphism</em></li>
<em><li>Run Time Polymorphism</em></li>
</ol>

<h2>A. COMPILE TIME POLYMORPHISM</H2>
The polymorphism which is implemented at the compile time is known as compile-time polymorphism.
<h2>B. RUN TIME POLYMORPHISM</H2>
<strong>Runtime polymorphism</strong> is also known as <strong>dynamic polymorphism</strong>. Function overriding is an example of runtime polymorphism. Function overriding means when the child class contains the method which is already present in the parent class. Hence, the child class overrides the method of the parent class. In case of function overriding, parent and child classes both contain the same function with a different definition. The call to the function is determined at runtime is known as runtime polymorphism.

<h2>INHERITANCE</h2>
Inheritance is a process in which one object acquires all the properties and behaviors of its parent object automatically. In such a way, you can reuse, extend or modify the attributes and behaviors which are defined in other classes. In C++, the class which inherits the members of another class is called
derived class and the class whose members are inherited is called base class. The derived class is the specialized class for the base class.

<h2>Syntax for C++ (INHERITANCE)</h2>
<pre>class derived_class :: visibility-mode base_class;</pre>

<strong>Types of Inheritance in C++ :</strong>
<ul>
<li>Single Inheritance</li>
<li>Multiple Inheritance</li>
<li>Hierarchical Inheritance</li>
<li>Multilevel Inheritance</li>
<li>Hybrid inheritance</li>
</ul>