Review of Fundamentals of Procedural Programming, Class and Objects, Data Abstraction, Information Hiding & Encapsulation, Constructors, destructors, and object creation, Name space and references , Class Methods , Methods Overloading , Inheritance , Polymorphism , Abstract Classes, Abstract Methods , Exceptions , Exception Handling.
🔄 Review of Fundamentals of Procedural Programming (प्रोसीजरल प्रोग्रामिंग के मूल)
- Procedural Programming एक स्टाइल है जिसमें प्रोग्राम को छोटे-छोटे फंक्शन्स या प्रोसिज़र्स में बांटा जाता है।
- डेटा और फंक्शन अलग-अलग रहते हैं।
- उदाहरण: C, Pascal
- Flow होता है: Start → Execute functions → End
🏷️ Class and Objects (क्लास और ऑब्जेक्ट्स)
- Class: एक ब्लूप्रिंट या टेम्पलेट होता है जिसमें डेटा और फंक्शन होते हैं।
- Object: Class का एक वास्तविक उदाहरण (instance)। जैसे “Car” class हो, तो “Honda” एक object।
🛡️ Data Abstraction, Information Hiding & Encapsulation
- Data Abstraction: केवल जरूरी चीज़ें दिखाना और बाकी छुपाना।
- Information Hiding: अंदर की जानकारी को बाहर से छुपाना ताकि एक्सेस कंट्रोल हो।
- Encapsulation: डेटा (variables) और उस पर काम करने वाले functions को एक साथ Class में रखना।
⚙️ Constructors, Destructors, and Object Creation
- Constructor: एक special method जो object बनाते समय अपने आप कॉल होता है और initial values सेट करता है।
- Destructor: object खत्म होने पर cleanup करता है।
- Object Creation: new keyword या direct declaration से object बनाना।
🏷️ Namespace and References
- Namespace: नामों को organize करने के लिए, ताकि naming conflicts न हों।
- References: किसी variable या object का alias या pointer, जिससे direct memory access होता है।
🧩 Class Methods and Method Overloading
- Class Methods: वे functions जो class के अंदर होते हैं और objects पर operate करते हैं।
- Method Overloading: एक ही नाम के कई methods जो अलग-अलग parameters लेते हैं।
🌳 Inheritance (विरासत)
- एक class दूसरी class से गुण (properties) और व्यवहार (methods) ले सकती है।
- Code reuse होता है और hierarchical relationship बनती है।
- Types: Single, Multiple, Multilevel Inheritance
🔄 Polymorphism (बहुरूपता)
- एक interface कई तरीकों से काम कर सकता है।
- दो प्रकार:
- Compile-time Polymorphism: Method overloading
- Run-time Polymorphism: Method overriding
🏛️ Abstract Classes and Abstract Methods
- Abstract Class: ऐसी class जिसे directly instantiate नहीं किया जा सकता, बस base class के रूप में उपयोग होता है।
- Abstract Method: बिना implementation के method, जो derived class में implement किया जाता है।
❗ Exceptions and Exception Handling
- Exception: प्रोग्राम के चलते अचानक आने वाली errors।
- Exception Handling: try, catch, finally blocks का उपयोग कर errors को संभालना ताकि प्रोग्राम crash न हो।
📚 संक्षेप सारांश:
कॉन्सेप्ट | विवरण |
---|---|
Procedural Programming | फंक्शन पर आधारित प्रोग्रामिंग |
Class & Objects | डेटा और फंक्शन का ब्लूप्रिंट और उसका उदाहरण |
Data Abstraction | जरूरी जानकारी दिखाना, बाकी छुपाना |
Encapsulation | डेटा और मेथड्स को क्लास में बांधना |
Constructor & Destructor | ऑब्जेक्ट की शुरुआत और अंत में स्वचालित कार्य |
Namespace & References | नामों का संगठन और संदर्भ |
Method Overloading | एक नाम के कई मेथड्स |
Inheritance | क्लास से गुण और व्यवहार लेना |
Polymorphism | एक interface के कई रूप |
Abstract Classes/Methods | बेस क्लास और बिना implementation वाले मेथड्स |
Exceptions | रनटाइम errors और उनका हैंडलिंग |
====================*****====================
🏛️ 1. Abstract Class (एब्सट्रैक्ट क्लास)
👉 परिभाषा:
Abstract class एक ऐसी class होती है:
- जिसे directly object बनाकर उपयोग नहीं किया जा सकता,
- पर उससे inherit करके नई class बनाई जाती है, जो उसकी methods को implement करती है।
✅ उपयोग कब करें?
जब आप चाहते हैं कि कुछ common structure तो सभी subclasses में हो, लेकिन हर subclass उसे अपने तरीके से implement करे।
📌 विशेषताएँ:
- इसमें abstract और concrete (normal) दोनों तरह की methods हो सकती हैं।
- इसका object नहीं बनता।
- इसे सिर्फ inherit किया जाता है।
📍 उदाहरण (C++ style):
// Abstract Class
class Shape {
public:
virtual void draw() = 0; // Abstract Method
};
// Subclass
class Circle : public Shape {
public:
void draw() override {
cout << "Circle draw हो रहा है" << endl;
}
};
🧩 2. Abstract Method (एब्सट्रैक्ट मेथड)
👉 परिभाषा:
Abstract Method वह होता है जो सिर्फ declared होता है, लेकिन उसका कोई body/implementation नहीं होता।
- इसे सिर्फ base class में declare किया जाता है।
- Derived class में इसे override करना ज़रूरी होता है।
उदाहरण:
virtual void draw() = 0;
यह एक pure virtual function है → यानी abstract method।
⚙️ Java में Abstract Example:
abstract class Animal {
abstract void sound(); // abstract method
}
class Dog extends Animal {
void sound() {
System.out.println("Bark");
}
}
🔄 Abstract Class बनाम Interface (Java/C# में):
Aspect | Abstract Class | Interface |
---|---|---|
Methods | Abstract + Concrete | केवल Abstract (Java 8+ में default भी) |
Inheritance | एक ही abstract class | कई interfaces implement कर सकते हैं |
Constructor | होता है | नहीं होता |
📚 सारांश (Summary):
टॉपिक | विवरण |
---|---|
Abstract Class | ऐसा base class जिसका object नहीं बनता |
Abstract Method | ऐसा method जिसका body नहीं होता |
उद्देश्य | Structure देना, implementation subclasses में छोड़ना |