Object Oriented Programming in Hindi: ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग

पोस्ट को शेयर करे!

हेल्लो दोस्तों स्वागत है आपका हमारी एक और C# Language कि फायदेमंद पोस्ट में। इस पोस्ट में Object Oriented Programming in Hindi यानि कि C# में ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग क्या है और OPP’s Concept के बारे में बोहोत ही आसान तरीके से आपकी सरल भाषा हिन्दी में दर्शाया गया है।

Join Telegram

Object Oriented Programming in Hindi (OPP’s Concept)

Article TypeC# Language
Article CategoryComputer
Article Nameऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग(OOP) क्या है?
Article LanguageHindi
Official Websiteshubhampal.co.in

ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग क्या है

object oriented programming in hindi
ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग क्या है?

Object Oriented Programming in Hindi: Object Oriented Programming एक patterns होता है जिसका उपयोग classes या objects का उपयोग करके programs को design करने के लिए किया जाता है। यह अपने concepts के माध्यम से Software Development और Maintenance को आसान बनाता है।

  1. Class (Logical Entity)
  2. Object (Runtime Entity)
  3. Constructor
  4. Polymorphism (Multi Behavior)
  5. Inheritance
  6. Encapsulation (Security)
  7. Abstraction (Elimination)
  8. Interface

1. Class

What is class in oops: C# में Class, properties और methods का एक collections होती है। Properties और methods दोनों ही एक class के member होते है। C# में classes को namespace के अंदर create किया जाता है तथा classes के अंदर हम user-defined methods और properties को create कर सकते है। Classes भी user-defined type होती है।

Example:

class class_name
{
	//data_members
	//member_function
}

2. Object

What is object in oops: C# में object एक runtime entity होता है। Object एक class type का variable है जिसका प्रयोग class के members को class के बाहर access करने के लिए किया जाता है।

किसी भी class के हम जितने चाहे उतने objects को आसानी से create कर सकते है। जब भी हम किसी भी class के object को create करते है तब उस class के सभी members को अपना एक memory address initialize कर दिया जाता है।

Object के द्वारा हम किसी भी class के static members को class के बाहर access नहीं कर सकते है, हम केवल class के instance variables को ही class के बाहर objects को create करके access कर सकते है।

Syntax:

class_name object_name = new class_name();

OR

class_name object_name; //declaration of object
object_name = new class_name();

Example:

class calculator
{
	int a,b;
	public void add()
	{
		"addition="+(a+b);
	}
}

Create a object of calculator class:

calculator cal = new calculator();         //first object
cal.a = 20;
cal.b = 30;
cal.add();
calculator cal1 = new calculator();          //second object
cal1.a = 20;
cal1.b = 30;
cal1.add();

3. Constructor

Constructor in hindi: Constructor class का एक method होता है जिसका नाम class name के समान ही होता है और Constructor का कोई भी return type नहीं होता है , शून्य भी नहीं |

Constructor को direct call करने की कोई जरुरत नहीं होती है, यह अपनाप ही automatically call हो जाता है जब भी आप उस Constructor की class के objects को create करते है।

Example:

namespace ConsoleApp24
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Calculator cal = new Calculator();
            cal.Addition();
            Calculator cal1=new Calculator();
            Cal1.Subtraction();
        }
    } 
  
   class Calculator
    {
        int a, b;
        static int c;
        static Calculator()
        {
            c = Convert.ToInt32(Console.ReadLine()); ;
        }
       public Calculator()
        {
            Console.WriteLine("Enter two numbers: ");
            a = Convert.ToInt32(Console.ReadLine());
            b = Convert.ToInt32(Console.ReadLine());
        }
        public Calculator(int a, int b) 
        {
            this.a = a;
            this.b = b;
        }
       public void Addition()
        {
            Console.WriteLine("Addition ="+(a+b));
        }
        public void Subtraction()
        {
            Console.WriteLine("Subtraction =" + (a - b));
        }
    }
}

OR

class Calculator
{
	int a,b;
	Bank bank = new Bank(100000, 12345, ”Techpile”);
}
class Bank
{
	int balance;
	int account;
	string holdername;
	public Bank(int blnc, int acno, string name)              //parameterized constructor	{
	balance = blnc;
	account = acno;
	holdername = name;
	
	}
	public void Withdraw(int wamount)
	{
	balance = balance - wamount;
	}
}

OR

class Bank
{
	int balance;
	int account;
	string holdername;
	public Bank()  				           //explicit default constructor
	{
	balance = 10000;
	account = 1000000;
	holdername = ”default”;
	} 
	public Bank (int blnc, int acno, string name)	       //parameterized constructor
	{
	balance = blnc;
	account = acno;
	holdername = name;
	}
}
Bank b = new Bank();
Bank b = new Bank(50000, 121334, ”Compiler”);

Types of Constructor

  1. Default Constructor
  2. Parameterized Constructor
  3. Copy Constructor

NOTE:

  1. Static constructor केवल एक ही बार execute होता है और Static constructor को हम parameterized नहीं बना सकते है।कुछ और भी होते Constructor होते है जैसे –
    • Static Constructor – Only default Constructor with static keyword
    • Private Constructor
  2. अगर हम किसी child class का object create करते हैं, तो child class का constructor implicitly, parent class के constructor को call करता है।
  3. अगर हम किसी child class का object create करते हैं, तो सबसे पहले parent class का Constructor execute होता है और फिर child class का Constructor execute होता है।

Constructor Overloading

Constructer overloading, Method overloading के जैसी ही होती है।

class NewClass
{
	int NewClass(int a, int b)
	{
	}
	int NewClass(int a, int b, int c)
	{
	}
	int NewClass(float a, float b)
	{
	}
	int NewClass(string name, int age)
	{
	}
	void NewClass(int age, string name)
	{
	}
}

4. Polymorphism

What is polymorphism in hindi: Polymorphism दो शब्दों से मिलकर बना होता है “poly” + “morphs” जिनका मतलब होता है many forms (कई रूप) अर्थात् Polymorphism का मतलब “many forms” होता है और Polymorphism तब होता है जब हमारे पास multiple classes होती हैं और सभी classes एक-दूसरे से inheritance के द्वारा inherit रहती है।

Polymorphism एक concept होता है जिसके द्वारा हम एक ही काम को multiple तरीकों से कर सकते हैं यानि कि जब एक single entity अलग-अलग cases में अलग-अलग behave करती है तो इसे Polymorphism कहा जाता है।

Types of Polymorphism

  1. Method Overloading (Static Polymorphism/Compile-Time Polymorphism)
  2. Method Overriding (Dynamic Polymorphism/Run-Time Polymorphism)

1) Method Overloading

What is method overloading: जब किसी एक class में different parameters के साथ same name के multiple methods होते हैं, तो इसे Method Overloading कहा जाता है।

Method Overloading में parameters तीन प्रकार से भिन्न हो सकते हैं।

  1. By different number of parameters
  2. By different data type of parameters
  3. By different sequence of parameters.

Example:

class Calculator
{
          void sub()
	  { 
	  }
      	  void Add(int a, int b)
	  {  
	  }
	  int void Add(int a, int b, int c)    //local scope
	  {
	  }
	  void Add(float a, float b)
	  {
	  }
	  void Add(double a, double b)
	  {	  
	  }
 }

OR

public class Cal
{  
     public static int add(int a,int b)
    {  
        return a + b;  
    }  
    public static int add(int a, int b, int c)  
    {  
        return a + b + c;  
    }  
}  
public class TestMemberOverloading  
{  
    public static void Main()  
    {  
        Console.WriteLine(Cal.add(12, 23));  
        Console.WriteLine(Cal.add(12, 23, 25));  
    }  
}  

2) Method Overriding

What is method overriding: Method Overriding का प्रयोग parent और child class में किया जाता है। जब हम किसी class में methods को create करते है और उसी class की child class में भी same name के methods को create करते है इसी को Method Overriding कहा जाता है।

Method Overriding के लिए parent class में methods को create करते समय virtual keyword का प्रयोग किया जाता है और child class में same name के methods को create करते समय override keyword का प्रयोग किया जाता है।

Example:

public class Animal
{  
         public virtual void eat()
        {  
        Console.WriteLine("Eating...");  
        }  
}  
public class Dog: Animal  
{  
        public override void eat()                                            //use override keyword
        {  
        Console.WriteLine("Eating bread...");  
       }  
}  
public class TestOverriding  
{  
        public static void Main()  
        {  
        Dog d = new Dog();  
        d.eat();  
       }  
}  

5. Inheritance

What is inheritance in hindi: Inheritance, object-oriented programming (OOP) का एक concept होता है जिसमे एक class किसी pre-existing class के सभी methods और properties का प्रयोग कर सकती है।

अगर कोई new class किसी pre-existing class के members को direct access करना चाहती है तो उस new class को उस pre-existing class का child होना जरुरी होता है जिस भी pre-existing class के members को वह new class, direct access करना चाहती है।

Inheritance एक एसी technique होती है जिसमे class के private members को छोड़कर class के सभी members को उस class की child class के द्वारा आसानी से access किया जा सकता है।

जिस भी pre-existing class को किसी new class के साथ में inherit किया जाता है उस pre-existing class को parent class/super class या base class कहते है और जिस new class में किसी pre-existing class को inherit किया जाता है उस new class को उस pre-existing class की sub class/child class या derived class कहते है। C# में Inheritance के लिए colon operator (:) का प्रयोग किया जाता है।

Example:

class Vehicle                                    //parent class
{
  public string brand = "Ford";            
  public void honk()                   
  {                    
    Console.WriteLine("Its Honk");
  }
}

class Car : Vehicle                                        // child class
{
  public string modelName = "Mustang";        
}

class Program
{
  static void Main(string[] args)
  {
    Car myCar = new Car();                               //object

    myCar.honk();                        // Call the honk() method from the Vehicle class

    Console.WriteLine(myCar.brand + " " + myCar.modelName);
  }
}

Types of Inheritance

  1. Single Inheritance: जब किसी class को केवल एक child class के साथ में inherit किया जाता है तो उसे Single Inheritance कहते है।
  2. Multilevel Inheritance: जब किसी class को एक child class के साथ में inherit किया जाता है और उस child class को भी किसी another class के साथ में inherit किया जाता है तब वह child class एक parent class की तरह behave करती है तो उसे Multilevel Inheritance कहते है।
  3. Multiple Inheritance: C# Language, Classes के Multiple Inheritance को support नहीं करती है लेकिन यह Interfaces का उपयोग करके Multiple Inheritance को support करती है। Interface , Abstract Methods का collections होता है।
  4. Hierarchical Inheritance: Hierarchical Inheritance में एक class एक से अधिक classes की parent हो सकती है।
  5. Hybrid Inheritance: Hybrid inheritance, Multiple inheritance और Hierarchical inheritance दोनों का ही combination होता है जिसमे एक class, multiple base classes से inherit होती है और वे सभी base classes भी standard base classes से inherit होती है।

6. Encapsulation

What is encapsulation in hindi: Encapsulation, object-oriented programming (OOP) का एक fundamental concept होता है जिसका प्रयोग मुख्यतः Data Security या Data Wrapping के लिए किया जाता है। Encapsulation, Data और data related operations को एक single unit या object में bundle करने के लिए refer करता है।

C# में Encapsulation को classes के उपयोग और Access Modifiers जैसे कि public, private और protected के माध्यम से achieve (प्राप्त) किया जाता है।

Encapsulation एक ऐसा concept  होता है जिसके द्वारा data को एक single unit में wrap किया जाता है जिससे की data हमेशा ही secure रहता है। Encapsulation के द्वारा data members और member functions को एक single unit में collect किया जाता है जिसको class कहते है।

Encapsulation का मुख्य उद्देश्य class के बाहर से data में किये जाने वाले changes को रोकना होता है और यह data केवल class के getter functions द्वारा ही access किया जा सकता है। एक fully encapsulated class में getter और setter functions होते है जिनका प्रयोग डाटा को read और write करने के लिए किया जाता है तथा यह class किसी भी data को direct access करने के लिए कभी भी allow नहीं करती है।

Example:

namespace AccessSpecifiers  
{  
    class Student  
    {  
        // Creating setter and getter for each property  
        public string ID { get; set; }  
        public string Name { get; set; }  
        public string Email { get; set; }  
    }  
}  

namespace AccessSpecifiers  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Student student = new Student();  
            // Setting values to the properties  
            student.ID = "101";  
            student.Name = "Mohan Ram";  
            student.Email = "mohan@example.com";  
            // getting values  
            Console.WriteLine("ID = " + student.ID);  
            Console.WriteLine("Name = " + student.Name);  
            Console.WriteLine("Email = " + student.Email);  
        }  
    }  
}  

7. Abstraction

What is abstraction in hindi: Abstraction  एक ऐसा process होता है जिसके द्वारा कुछ ऐसा data जोकि user के लिए जरुरी  नहीं होता है उस data को hide कराकरके user को केवल आवश्यक data (essential information) को ही show कराया जाता है।

C# में Abstraction का प्रयोग मुख्यतः Data Hiding के लिए किया जाता है और Abstraction को Abstract classes या Interfaces के साथ में achieve (प्राप्त) किया जा सकता है। Abstraction में Abstract Classes और Abstract Methods को create करने के लिए मुख्यतः Abstract keyword का प्रयोग किया जाता है।

Abstract Class

Abstract class in c#: एसी class जिसके members Abstract और Non-Abstract दोनों ही प्रकार के होते है उसको Abstract class कहते है यानि कि Abstract class एक Half-Implemented class होती है जिसमे Abstract और Non-Abstract दोनों ही प्रकार के members होते है।

Abstract class अपने child classes के लिए एक prototype तैयार करती है तथा Abstract class कभी भी independently काम नहीं कर सकती है।

Abstract class एक restricted class होती है जिसका प्रयोग हम कभी भी objects को create करने के लिए नहीं कर सकते है और अगर हम Abstract class का प्रयोग objects को create करने के लिए करना चाहते है तो यह जरुरी होता है कि वह Abstract class किसी दूसरी class के साथ में inherit होनी चाहिए जिससे कि हम class के members को आसानी से access कर सके |

Abstract Method

Abstract method in c#: Abstract method का प्रयोग केवल एक Abstract class में ही किया जा सकता है और Abstract method की कोई भी body या definition नहीं होती है इन्हें केवल declare करके ही छोड़ दिया जाता है। Abstract method को body उस class के द्वारा provide होती है जिस भी class को Abstract class के साथ में inherit किया गया होता है।

Example:

class  class1
{
         abstract void Add();            //declaration of function
         void sub();                              //definition of function
         {
         }
}
class class2:class1
{
         void Add();           //overriding the abstract member of parent class
}

OR

abstract class Animal
{
  public abstract void animalSound();
  public void sleep()
  {
    Console.WriteLine("Zoo");
  }
}

8. Interface

Interface in oops: C# में Abstraction को achieve (प्राप्त) करने का दूसरा तरीका Interfaces के साथ में होता है। एक Interface completely एक Abstract Class होता है, जिसमे केवल Abstract methods और properties हो सकते है।

Example:

interface Animal
{
          void animalSound();                        // interface method (does not have a body)
          void run();                               // interface method (does not have a body)
}

निष्कर्ष – ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग

दोस्तों मैं उम्मीद करता हूँ कि मैंने इस पोस्ट के माध्यम से आपको Object Oriented Programming in Hindi यानि कि C# में ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग क्या है और OPP’s Concept के बारे में बताया है उन्हें आप बोहोत ही आसानी से समझ गए होंगे गए होंगे क्यूंकि मैंने इस पोस्ट के माध्यम से आपको बोहोत ही आसानी से यह समझाने का पूर्णतः प्रयास किया है कि आप कैसे C# में OPP’s के सभी concepts का प्रयोग कर सकते है।


पोस्ट को पूरा पढने के लिए धन्यवाद ! अगर आपका इस पोस्ट से सम्बन्धित कोई भी प्रश्न है तो आप नीचे कमेंट करके पूंछ सकते है |

यह भी पढ़ें –

Loading

5/5 - (2 votes)
पोस्ट को शेयर करे!

Leave a Comment

error: Content is protected !!