
Inheritance In Java In Hindi
आज के इस article में हम Inheritance In Java In Hindi Hindi के बारे में जानेंगे। Java में Inheritance कितने प्रकार की होती है के बारे में भी जानेंगे।
Inheritance In Java In Hindi
Java में Inheritance एक ऐसा mechanism है जिसमें एक object एक parent object की सभी properties और behavior को acquire कर लेता है। यह OOPs (Object Oriented programming systems) का एक महत्वपूर्ण हिस्सा है।
Java में Inheritance के पीछे का विचार यह है कि आप new classes बना सकते हैं जो existing classes पर बनाए गए हैं। जब आप किसी existing class से इनहेरिट करते हैं, तो आप parent class के methods और fields का पुन: उपयोग कर सकते हैं।
इसके अलावा, आप अपनी current class में भी नए methods और fields को जोड़ सकते हैं। Inheritance IS-A relationship को representकरता है जिसे parent-child का relationship से भी जाना जाता है।
Inheritance में use होने वाली Terms
Class: Class एक objects का एक समूह है जिसकी common properties होती हैं। ये यू कहें एक टेम्प्लेट या ब्लूप्रिंट है जिससे ऑब्जेक्ट बनाए जाते हैं।
Subclass/Child Class: Subclass एक एसी class है जो दूसरी class को inherit करती है। इसे derived class या extended class और child class भी कहा जाता है।
Super Class/Parent Class: Superclass वह class है जहाँ से एक subclass को features मिलते हैं। इसे base class या parent class भी कहा जाता है।
Reusability: जैसा कि नाम पता चल रहा है,reusability एक mechanism है जो आपको एक new class बनाते समय existing class के methods और fields का पुन: उपयोग करने की सुविधा देता है। आप previous class में पहले से defined methods और fields का उपयोग कर सकते हैं।
Java Inheritance का Syntax
class Subclass-name extends Superclass-name
{
//methods and fields
}
यहाँ पर extends keyword ये indicates करता है कि आप एक new class बना रहे हैं, जो existing class से निकला है। “Extends” का अर्थ functionality को बढ़ाना है।
Java Inheritance के Types
Java में पाँच प्रकार की Inheritance होती है: single, multilevel और hierarchical। बाकी दो multiple और hybrid को interface के द्वारा किया जाता है।
1. Single Inheritance: जब एक class दूसरी class को inherits में लेता है, तो इसे single inheritance कहा जाता है।
2. Multilevel Inheritance: जब inheritance की एक chain होती है, तो इसे multilevel inheritance कहा जाता है।
3. Hierarchical Inheritance: Hierarchical inheritance में दो या दो से अधिक classes को एक ही class को inherit करती हैं।