हेल्लो दोस्तों! आज हम इस article में Method Hiding in Java in Hindi (जावा में मेथड हाईडिंग क्या है?) के बारें में पढेंगे और इसके example को भी देखेंगे, तो चलिए शुरू करते हैं:-
Method Hiding in Java in Hindi
यदि child class और parent class दोनों के पास same (समान) name और समान parameter की static method होती है. तो child class की method के द्वारा parent class की method को hide कर दिया जाता है. इसे ही method hiding कहते हैं.
Method hiding एक functionality है और यह केवल static method के साथ ही work करती है. यह method overriding से different होती है. क्योंकि java में static method को override नहीं किया जा सकता.
इसे पढने के लिए click करें:- method overriding क्या है?
Features of method hiding –
- method hiding को compile-time polymorphism और static polymorphism या early binding भी कहते है.
- इसमें method call को हमेशा java compiler के द्वारा reference type के आधार पर resolve किया जाता है.
- इसमें parent और child class की मेथड static होनी चाहिए.
example –
तो चलिए अब इसके उदाहरण को भी देख लेते हैं:-
class First{
public static void exampleMethod() {
System.out.println("this is method of parent class");
}
}
public class Second extends First {
public static void exampleMethod() {
System.out.println("this is method of child class");
}
public static void main(String args[] ) {
Second.exampleMethod();
}
}
इसका आउटपुट:- this is method of child class
Summary (सारांश)
जावा में Method Hiding को समझना बहुत ज़रूरी है, खासकर उन छात्रों के लिए जो OOPs concepts और polymorphism पढ़ रहे हैं। इस article में आपको सीखने को मिलेगा कि Method Hiding तब होती है जब child और parent class दोनों में एक ही नाम और parameters वाली static method मौजूद हो। यहाँ child class की method parent class की method को hide कर देती है। यह article बताता है कि Method Hiding और Method Overriding में क्या अंतर है, क्योंकि static methods को override नहीं किया जा सकता। आप इसे compile-time polymorphism या early binding भी कह सकते हैं। उदाहरणों के साथ यह स्पष्ट किया गया है कि method call को reference type के आधार पर resolve किया जाता है। इस विषय को पढ़ने से छात्रों को exam preparation में मदद मिलेगी, क्योंकि यह Java मल्टीथ्रेडिंग या error handling नहीं, बल्कि static methods के व्यवहार पर आधारित एक कॉमन MCQ टॉपिक है।
- Method Hiding केवल static methods के साथ work करता है।
- यह class के reference type पर निर्भर करता है, न कि object type पर।
- Overriding से अलग, static methods को override नहीं किया जा सकता।
- Example को implement करके आप runtime behavior को समझ सकते हैं।
- इससे OOPs में polymorphism और inheritance के concept मजबूत होते हैं।
निवेदन:- अगर आपके लिए यह आर्टिकल useful रहा हो तो इसे अपने दोस्तों के साथ अवश्य share कीजिये और आपके java से related कोई question हो तो आप उसे नीचे comment करके बता सकते हैं. Thanks.