Method Hiding in Java in Hindi – जावा में method hiding क्या है?

हेल्लो दोस्तों! आज हम इस 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

निवेदन:- अगर आपके लिए यह आर्टिकल useful रहा हो तो इसे अपने दोस्तों के साथ अवश्य share कीजिये और आपके java से related कोई question हो तो आप उसे नीचे comment करके बता सकते हैं. Thanks.

Leave a Comment