What is Inheritance in Java in Hindi ??? Single, Multilevel ?????? Hierarchical
?????????????????? ?????????????????????, ??????????????? Java Programming ??????????????? ????????? ???????????? ?????????????????? ????????? ??????????????? ??????????????? ????????? ???????????? Class ?????? Object ?????? ???????????? ???????????? ????????? ?????? ?????? OOPs ?????? ???????????? ?????? ???????????? ?????????????????????????????? ?????????????????? (Pillar) ????????????????????? ??? Inheritance in Java in Hindi (??????????????????????????????)???
??????????????????, ????????? ???????????? ?????????????????? ?????? ????????? ?????? ?????? ?????? ????????? ??????, ?????? ???????????? ???????????? ?????? ?????? ?????? ????????? ?????????????????? ?????????????????? ?????? ??????????????? ??????? ????????????! ?????? ???????????? "??????????????????" (Inheritance) ????????? ????????? ???????????? ???????????? ?????????????????? ????????? ?????? ????????? ?????? ???????????? ????????? ????????? ???????????? ?????? ??????????????? ????????? ????????? ????????? ???????????? ??????, ?????? ?????? ??????????????? ??????????????? ????????? ????????? ?????????????????? ??????????????? ?????? ????????????, ????????? "Inherit" (????????????) ?????? ???????????? ????????????
?????? ??????????????? ????????? ?????? ????????????????????? ?????? Inheritance ???????????? ???????, extends ?????????????????? ?????? ??????????????? ???????????? ???????????? ?????? ???????????? ?????????????????? (Types) ???????????? ??????????
What is Inheritance in Java in Hindi? - ???????????? ????????? ?????????????????????????????? ???????????? ???????
Inheritance ?????? ????????? ??????????????????????????? ?????? ?????????????????? ?????? ??????????????? (Child Class) ??????????????? ??????????????? (Parent Class) ?????? ?????????????????????????????? (Variables) ?????? ???????????????????????? (Methods) ?????? ???????????? ???????????? ?????????
???????????????: ????????? ?????? ?????????????????? ???????????? ??????????????? ???????????? (Code Reusability) ???
Father-Son Example (?????????-???????????? ?????? ??????????????????)
- Parent Class (Super Class): ???????????? (??????????????? ????????? ???????????? ?????? ????????? ?????????)???
- Child Class (Sub Class): ???????????? (?????? ???????????? ?????? ????????? ???????????? ?????? + ???????????? ????????? ?????? ?????? ????????? ?????? ????????? ???????????? ??????)???
Syntax & 'extends' Keyword
?????????????????? ???????????? ?????? ????????? ?????? extends ?????????????????? ?????? ???????????????????????? ???????????? ????????????
class Child extends Parent {
// ?????? Child ?????? ????????? Parent ?????? ?????? ????????? ??? ?????????
}
Types of Inheritance in Java in Hindi - ???????????? ????????? ?????????????????????????????? ?????? ??????????????????
Java ????????? ??????????????? ????????? ?????? 3 ????????? ?????? ?????????????????????????????? ???????????????????????? ?????????:
1. Single Inheritance
?????? ?????? ???????????? ????????? ?????? ??????????????? ??????????????? ?????? ??????????????? ???????????? ?????? ?????? ?????? ??????????????? ?????????????????????????????? ?????????????????? ?????????
(Class B extends Class A)
2. Multilevel Inheritance
???????????? ?????? -> ???????????? ?????? -> ???????????????
(Class C extends Class B, Class B extends Class A)
???????????? ???????????? (C) ?????? ???????????? (B) ?????? ???????????? (A) ??????????????? ?????? ????????? ??????????????? ????????????
3. Hierarchical Inheritance
?????? ???????????? ?????? ?????? ?????? ?????? ?????????????????? ???????????? ???????????? ?????? ?????? ????????? Hierarchical Inheritance ????????? ???????????? ?????????
(Class B extends Class A, Class C extends Class A)
???????????? ?????? ?????? Parent Class ?????? ?????? Child Classes ?????????????????? ????????????
(?????????: Java ????????? Multiple Inheritance (?????? ???????????? ?????? ?????? ????????????) ????????????????????? ?????? ??????????????? ?????????????????? ???????????? ??????????????? ????????? ?????? Interface ?????? ??????????????? ???????????? ????????????)
Java Inheritance Code Example
???????????? Single Inheritance ?????? ?????? ???????????? ?????????????????? ??????????????? ????????????
// Parent Class
class Animal {
void eat() {
System.out.println("This animal eats food.");
}
}
// Child Class
class Dog extends Animal {
void bark() {
System.out.println("The dog barks.");
}
}
// Main Class
public class Main {
public static void main(String[] args) {
Dog d = new Dog();
d.bark(); // Child method
d.eat(); // Parent method
}
}
Output:
The dog barks.
This animal eats food.
Conclusion ??? ????????????????????????
???????????? ?????????????????? ?????? ?????? ?????? ??????????????? ?????? ???????????? Inheritance in Java in Hindi ?????? ??????????????? ?????? ????????? ???????????? ???????????????
????????? ????????????: ?????? ?????? ???????????? ????????? ?????? ?????? ????????????????????? ????????? "Is-A" ?????????????????? ?????? (???????????? Dog is an Animal), ?????? ???????????? Inheritance ????????? ???????????????
???????????? ??????????????? ????????? ?????? OOPs ?????? ??????????????? ???????????? "Polymorphism in Java" ?????????????????????, ??????????????? ???????????? ?????? "?????? ?????????, ???????????? ?????????"???
FAQs
Q1. Java ????????? Multiple Inheritance ??????????????? ???????????? ?????????????
Ans: ????????????????????? ????????? ?????? Parents ?????? ????????? ????????? ????????? ?????? ???????????? ??????, ?????? Child ????????????????????? ?????? ?????????????????? ?????? ??????????????? ???????????? ????????? ???????????? (????????? Diamond Problem ???????????? ?????????)???
Q2. Super Class ?????? Sub Class ???????????? ???????
Ans: ??????????????? ??????????????????????????? ?????? ?????? ????????? ?????? ?????? Super (Parent) ??????, ?????? ?????? ?????? ????????? ?????? ?????? Sub (Child) ?????????
Q3. ???????????? ?????? Private members ?????? inherit ?????? ???????????? ??????????
Ans: ????????????, Parent class ?????? ???????????????????????? ??????????????? ?????? Child class ?????????????????? ???????????? ?????? ???????????????