Skip to main content

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

Popular posts from this blog

    METACHAR ACTER   UNIX  shell  เค…เคจेเค• เคฎेเคŸाเคšाเคฐेเค•्เคŸเคฐ เคช्เคฐोเคตाเค‡เคก เค•เคฐเคคा เคนै เคœो เค•िเคธी เคญी เคถैเคฒ เคธ्เค•เคซ्เคฐिเคช्เคค เคฎें เค‰เคจเค•ा เค‰เคธे เค•เคฐเคคे เคŸाเค‡เคฎ เคตिเคทेเคธ เคฎाเค‡เคจिंเค— เคฐเค–เคคे เค”เคฐ เคœเคฌ เคคเค• เค•ाเคถी เคธोเคตเคณे เคจเคนीं เคนो เคœाเคคे เคคเคฌ เค•ाเคŸ เค•िเคธी เคตเคฐ्เคก เค•ा เคंเคกिंเค— เค•ा เค•ाเคฐเคจ เคฌเคจเคคे เคนै।                                                     ex:--     เคเค• directory เคฎें เคซिเคฒो เค•ो เคฒिเคธ्เคŸिंเค— เค•เคฐเคคे เคŸाเค‡เคฎ เคเค• เคธिंเค—เคฒ เคšैเคฐेเค•्เคŸเคฐ เคฎें เคฐเค–ा เคœाเคคा เคนै เค”เคฐ * เคเค• เคธे เค…เคงिเค• เคตเคฐ्เคก เค•ो เคฎैเคšेเคธ เค•เคฐเคคा เคนै เคฏเคน เคถैเคฒ เค•े เค…เคงिเค•ांเคถ เคชเคค्เคฐों เค•ो เคฒिเคธ्เคŸ เคฆी เค—เคฏी เคนै เคœिเคจ्เคนे metacharacter เคฌोเคฒा  เคœाเคคा เคนै.   * ? [ ] " ' \    /    $ : ; ( ) | ^ < >  \.   เคจเคˆ เคฒाเค‡เคจ เคธ्เคชेเคธ เคคเคฌ   #!/bin/sh  echo hello; word  #!/bin/sh  echo "I have \$1200" 1. <  single quotes : all special charecters between these quotes lose their special.  ex. --...
UNIX in Hindi UNIX เคเค• multi tasking, multi user operating system  เคนै เคœिเคธे เคธเคจ 1969  เคฎें AT & T LABS  เคฎें เคฌเคจाเคฏा เค—เคฏा เคฅा। เคœिเคธे AT & T เคฎें เค•ाเคฎ เค•เคฐเคจे เคตाเคฒे computer  scientist  ken Thompson  &   Denis Ritchie and  เค‰เคจเค•े friends เคจे เคฎिเคฒเค•เคฐ  เคฌเคจाเคฏा เค—เคฏा เคฅा.  เคเคธे AT & T   เคจे เค…เคชเคจे เค‰เคธे เค•े เคฒिเค เคฌเคจाเคฏा เค—เคฏा เคฅा เคฒेเค•िเคจ เคฌाเคฆ เคฎें เคธเคจ 1970 เคฎें เค‡เคธे commercialize เค•เคฐ เคฆिเคฏा เค—เคฏा เคฅा।  เค‡เคธ Operating System เค•ो เฅ™ाเคธ เคคौเคฐ เคชเคฐ Programmers เค”เคฐ developers เค•े เคฒिเค เคฌเคจाเคฏा เค—เคฏा เคฅा। เค‡เคธเค•ी เคฌเคœเคน เคฏเคน เคฅी เค•ी เคฏเคน Modular Programming Interface design provide เค•เคฐเคคा เคฅा เคœिเคธे "Unix Philosophy" เคญी เค•เคนा เคœाเคคा เคนै। UNIX Operating System เค•ो 'C' เค”เคฐ Assembly Programming Languages เคฎें เคฒिเค–ा เค—เคฏा เคฅा। C Programming language เค•ो เค–ाเคธ เคคौเคฐ เคชเคฐ UNIX เคฌเคจाเคจे เค•े เคฒिเค เคนी develop เค•िเคฏा เค—เคฏा เคฅा เค”เคฐ เค‡เคธे เคญी Denis Ritchie เคฆ्เคตाเคฐा เคนी เคฌเคจाเคฏा เค—เคฏा เคฅा। เค†เคœ เคญी 'C' Programming Language เค•ो เคฌเคนुเคค เฅ™ाเคธ เคฎाเคจा เคœाเคคा เคนै เค•्เคฏूंเค•ि Device Drivers เค‡เคธी language เคฎें เคœ्เคฏाเคฆाเคคเคฐ เคฒिเค–े เคœाเคคे เคนैं เค”เคฐ เคธाเคฅ เคนी เค‡เคธे  Mother...
Addressing modes of microprocessor 8085 The way of specifying data to be operated by an instruction is called addressing Types of addressing modes – In 8085 microprocessor there are 5 types of addressing modes: Immediate Addressing Mode – In immediate addressing mode the source operand is always data. If the data is 8-bit, then the instruction will be of 2 bytes, if the data is of 16-bit then the instruction will be of 3 bytes. Examples: MVI B 45 (move the data 45H immediately to register B) LXI H 3050 (load the H-L pair with the operand 3050H immediately) JMP address (jump to the operand address immediately). Register Addressing Mode – In register addressing mode, the data to be operated is available inside the register(s) and register(s) is(are) operands. Therefore the operation is performed within various registers of the microprocessor. Examples: MOV A, B (move the contents of register B to register A) ADD B (add contents of registers A and B and s...