Principles of Object Oriented Programming (OOP) ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग के सिद्धांत

🌟 Introduction (परिचय)

Object-Oriented Programming (OOP) is the foundation of Java. It solves the problems of older languages like C or Pascal by organizing programs around real-world entities such as objects and classes. Java follows 8 main principles of OOP. Let’s explore them one by one in detail with English-Hindi explanation and examples.


✅ 1. Object (ऑब्जेक्ट)

An object is a real-world entity. It is the basic unit of OOP. Objects hold data (variables) and functions (methods) to process that data.

📌 Example of objects in real life: Car, Student, Account, Mobile.

📘 Programming View:
Objects are created from a class and occupy memory. They communicate using messages.

🟣 हिन्दी में समझें:
ऑब्जेक्ट, OOP की मूल इकाई होती है। इसमें डेटा और फंक्शन होते हैं। यह मेमोरी में स्थान घेरता है और अन्य ऑब्जेक्ट्स से मैसेज द्वारा संवाद करता है।


✅ 2. Class (क्लास)

A class is like a template or blueprint for objects. It defines what data and methods an object will have.

📘 Syntax:

class Employee {
    int empId;
    public void getEmp() { }
    public void setEmp() { }
}

📘 Creating object:

Employee e = new Employee(); // Object of class Employee

🟣 हिन्दी में समझें:
क्लास एक एब्सट्रैक्ट डेटा टाइप (ADT) है जिसमें डेटा मेम्बर्स और फंक्शन होते हैं। ऑब्जेक्ट क्लास से ही बनते हैं।


✅ 3. Data Abstraction (डेटा एब्सट्रेक्शन)

Data Abstraction means showing only important information and hiding internal details.

📌 Example: When you use a calculator, you press buttons, but don’t see the internal working.

🟢 In Java, we use private data and public methods to achieve abstraction.

🟣 हिन्दी में समझें:
जरूरी जानकारी दिखाना और बाकी को छिपाना ही डेटा एब्सट्रेक्शन है। जैसे हम कार चलाते हैं, लेकिन उसके इंजन का काम नहीं जानते।


✅ 4. Encapsulation (इनकैप्सुलेशन)

Encapsulation means binding data and methods together in a class. It protects data from unauthorized access.

📘 Example:

class Bank {
    private int balance;
    public void deposit(int amount) {
        balance += amount;
    }
}

🟣 हिन्दी में समझें:
जब हम डेटा और फंक्शन को एक ही क्लास में जोड़ते हैं, उसे इनकैप्सुलेशन कहते हैं। इससे डेटा सुरक्षित रहता है।


✅ 5. Inheritance (इनहेरिटेंस)

Inheritance allows one class to inherit features (data & functions) of another class.

📘 Java supports:

  • Single

  • Multilevel

  • Hierarchical

  • (Java doesn’t support multiple inheritance using classes directly, but via interfaces)

📘 Example:

class Animal {
    void eat() {}
}
class Dog extends Animal {
    void bark() {}
}

🟣 हिन्दी में समझें:
जब एक क्लास, दूसरी क्लास से गुण प्राप्त करती है, उसे इनहेरिटेंस कहते हैं। इससे कोड को बार-बार नहीं लिखना पड़ता।


✅ 6. Polymorphism (पालीमोर्फिस्म)

Polymorphism = One name, many forms
A method or operator behaves differently in different contexts.

📘 Two types:

  • Compile-Time Polymorphism (Method Overloading, Operator Overloading)

  • Run-Time Polymorphism (Method Overriding with Virtual Functions)

📘 Example (Overloading):

class Math {
    int add(int a, int b) { return a + b; }
    double add(double a, double b) { return a + b; }
}

🟣 हिन्दी में समझें:
जब एक ही फंक्शन का अलग-अलग उपयोग किया जाता है, तो उसे पालीमोर्फिस्म कहते हैं। यह OOP का बहुत ही शक्तिशाली फीचर है।


✅ 7. Dynamic Binding (डायनामिक बाइंडिंग)

Binding means linking a method call to its definition.

Dynamic Binding happens at runtime, not compile-time.

📘 Example:

Animal a = new Dog(); 
a.eat();  // eat() of Dog is called at runtime

🟣 हिन्दी में समझें:
जब किसी मेथड का निर्धारण रनटाइम पर होता है, उसे डायनामिक बाइंडिंग कहते हैं। यह इनहेरिटेंस और पालीमोर्फिस्म में उपयोग होता है।


✅ 8. Message Passing (मैसेज पासिंग)

Objects communicate with each other by sending messages (method calls).

📘 Syntax:

Student s = new Student();
s.setStudent(); // message passing

🟣 हिन्दी में समझें:
जैसे लोग बात करते हैं, वैसे ही ऑब्जेक्ट आपस में मैसेज के जरिए संवाद करते हैं। यह सिस्टम को वास्तविक दुनिया के जैसा बनाता है।


📘 Summary Table: OOP Principles

Principle Description (English) विवरण (हिन्दी में)
Object Real-world entity with data & methods डेटा और फंक्शन से बना यूनिट
Class Blueprint of object ऑब्जेक्ट की रूपरेखा
Abstraction Show essential info, hide details जरूरी जानकारी दिखाना, बाकी छुपाना
Encapsulation Bind data and methods together डेटा और फंक्शन को जोड़ना
Inheritance One class inherits from another एक क्लास का गुण दूसरी में आना
Polymorphism One function, many uses एक नाम, कई काम
Dynamic Binding Link method at runtime मेथड का निर्धारण रनटाइम पर होना
Message Passing Objects interact via messages ऑब्जेक्ट्स का संवाद

Comments

Popular posts from this blog

web browser वेब ब्राउज़र

Java's support system जावा का सहयोगी तंत्र

Java and Internet जावा और इंटरनेट