Java Inheritance
Introduction to Java Inheritance
Inheritance เคा เคเคธा Machanisam เคนै เคिเคธเคฎे เคเค old class เคธे new class create เคिเคฏा เคाเคคा เคนे เคเคธ เคे เคฆ्เคตाเคฐा old class เคी properties เคो new class เคฎें เคช्เคฐเคฏोเค เคिเคฏा เคाเคคा เคนे old class เคी properties เคो new class เคฎें เคช्เคฐเคฏोเค เคเคฐเคจे เคे เคฒिเค old class เคी inherit เคเคฐเคจा เคนोเคคा เคนै| เคเคฐ class เคो inherit เคเคฐเคจे เคे เคฒिเค derivation public, private and protected เคा เคช्เคฐเคฏोเค เคिเคฏा เคाเคคा เคนै|
inheritance เคฎें old class เคो base class เคฏा parent class or super class เคเคนा เคाเคคा เคนै, เคिเคธ class เคी property เคฒी เคाเคคी เคนै| เคเคฐ เคจเค class เคो child class เคฏा derive class เคฏा sub class เคเคนा เคाเคคा เคนै, เคिเคธ class เคे เคฆ्เคตाเคฐा property เคฒी เคाเคคी เคนै|
เคเคธा เคเคฐเคจे เคे เคฒिเค เคो class methods เคो access เคเคฐเคจा เคाเคนเคคी เคนै เคเคธे เคฆूเคธเคฐी class เคी sub class เคฌเคจเคจा เคนोเคा। Sub class เคฌเคจเคจे เคे เคฒिเค เคเคชเคी class เคो เคเคธ เคฆूเคธเคฐी class เคो extend เคเคฐเคจा เคนोเคा। เคเคธे เคนी inheritance เคเคนเคคे เคนै।
Inheritance เคธे เคเคช เคเค เคนी code เคो เคฌाเคฐ เคฌाเคฐ เคฒिเคเคจे เคी เคเคฒเคเคจ เคธे เคฌเค เคाเคคे เคนै। Inheritance เคी เคเคธ เคूเคฌी เคो re-usability เคเคนเคคे เคนै। เคฏाเคจि เคเค เคนी code เคो เคฌाเคฐ เคฌाเคฐ เค
เคฒเค เค
เคฒเค เคเคเคน เคชเคฐ reuse เคिเคฏा เคा เคธเคเคคा เคนै।
เคเคฌ เคोเค เคเค class เคฆूเคธเคฐी class เคो inherit เคเคฐเคจा เคाเคนเคคी เคนै เคคो เคตเคน extends keyword เคฏूเค़ เคเคฐเคคी เคนै। เคเคฐ เคฏเคฆि เคเคช เคाเคนเคคे เคนै เคी เคเคชเคे เคे เคฆ्เคตाเคฐा เคฌเคจाเคฏीं เคนुเค class เคो เคोเค เคฆूเคธเคฐी class inherit เคจा เคเคฐे เคคो เคเคธเคे เคฒिเค เคเคช class เคे เคจाเคฎ เคธे เคชเคนเคฒे final keyword เคฒเคा เคฆेเคคे เคนै। เคिเคจ classes เคे เคจाเคฎ เคธे เคชเคนเคฒे final keyword เคนोเคคा เคนै เคเคจ्เคนें inherit เคจเคนीं เคिเคฏा เคा เคธเคเคคा เคนै।
เคोเค เคญी class เคธिเคฐ्เคซ เคเค เคนी class เคो extend เคเคฐ เคธเคเคคी เคนै। เคเคฌ เคोเค class เคเค เคธे เค
เคงिเค classes เคो extend เคเคฐเคคी เคนै เคคो เคตเคน multiple inheritance เคเคนเคฒाเคคा เคนै। เคเคฐ เคฎें เคเคชเคो เคฌเคคाเคจा เคाเคนเคคा เคนुँ เคी เคाเคตा เคฎें multiple inheritance allow เคจเคนीं เคนै। เคเคธเคी เคเคเคน เคชเคฐ เคเคช multilevel inheritance implement เคเคฐ เคธเคเคคे เคนै।
เคिเคธ class เคो inherit เคिเคฏा เคाเคคा เคนै เคตเคน super class เคเคนเคฒाเคคी เคนै। เคเคฐ เคो class inherit เคเคฐเคคी เคนै เคตเคน sub class เคเคนเคฒाเคคी เคนै। เคฏँเคนा เคชเคฐ เคเค เคง्เคฏाเคจ เคฆेเคจे เคฏोเค्เคฏ เคฌाเคค เคฏे เคนै เคी sub class super class เคे เคธเคญी methods เคเคฐ variables เคो access เคจเคนीं เคเคฐ เคธเคเคคी เคนै।
เคो methods public เคเคฐ protected declare เคिเคฏे เคนुเค เคนै เคเคจ्เคนें เคนी sub class access เคเคฐ เคธเคเคคी เคนै। Superclass เคे เคिเคธी เคญी private member เคो subclass access เคจเคนीं เคเคฐ เคธเคเคคी เคนै। เคฏเคฆि superclass เคจे เคिเคธी เคเคฐ class เคो extend เคเคฐ เคฐเคा เคนै เคคो เคเคธ class เคे เคญी เคธเคญी public เคเคฐ protected members เคो เคเคชเคी class เคฏूเค़ เคเคฐ เคธเคเคคी เคนै।
Types of Java Inheritance
Java เคฎें 3 เคคเคฐเคน เคธे inheritance เคो เคฏूเค़ เคिเคฏा เคाเคคा เคนै। เคเคชเคी application เคे เคฒिเค เคเคชเคो เคो suitable เคฒเคे เคเคช เคตเคนी เคคเคฐीเคा เคฏूเค़ เคเคฐ เคธเคเคคे เคนै। เคเคจ เคคीเคจों เคคเคฐीเคों เคे เคฌाเคฐे เคฎें เคจिเคे เคฆिเคฏा เคा เคฐเคนा เคนै।
SINGLE INHERITANCE
Single inheritance เคฎें เคเค class เคिเคธी เคฆूเคธเคฐी เค्เคฒाเคธ เคो extend เคเคฐเคคी เคนै। เคเคธ เคคเคฐเคน เคे เคे inheritance เคा เคเคชเคฏोเค basic programming เคฎें เคिเคฏा เคाเคคा เคนै।
MULTILEVEL INHERITANCE
Multilevel inheritance เคฎें เคเค class เคฆूเคธเคฐी class เคो extend เคเคฐเคคी เคนै เคเคฐ เคฆूเคธเคฐी class เคคीเคธเคฐी class เคो extend เคเคฐเคคी เคนै।
HIERARCHICAL INHERITANCE
Hierarchical inheritance เคฎें เคเค class เคो เคฌเคนुเคค เคธी classes extend เคเคฐเคคी เคนै। เคเคธ เคคเคฐเคน inheritance เคा เคช्เคฐเคฏोเค เคเคฌ เคिเคฏा เคाเคคा เคเคฌ super class เคे task เคे เคเค sub task เคนोเคคे เคนै।
Inheriting a Class
เคฏเคฆि เคเคช เคिเคธी class เคो inherit เคเคฐเคจा เคाเคนเคคे เคนै เคคो เคเคช extends เคीเคตเคฐ्เคก เคเคธे เคเคฐเคคे เคนै। เคเคช เค
เคชเคจी class เคे เคจाเคฎ เคे เคฌाเคฆ extends keyword เคฒเคाเคคे เคนै เคเคฐ เคเคธเคे เคฌाเคฆ เคเคช เคिเคธ class เคो inherit เคเคฐเคจा เคाเคนเคคे เคนै เคเคธ class เคा เคจाเคฎ เคฒिเคเคคे เคนै। Inheritance เคा เคเคฆाเคนเคฐเคฃ เคจिเคे เคฆिเคฏा เคा เคฐเคนा เคนै।
class A
{
public void display() { System.out.println(“This is A class”); } public static void main(String args[]) { display(); }
}
class B
extends A
{
public static void main(String args[]) { display(); }
}
|
Comments
Post a Comment