Java Abstract Class In Hindi (जावा Abstract Class क्या हैं ?)

 

Java Abstract Class In Hindi

Java Abstract Class In Hindi :

वह Class जो abstract कीवर्ड के साथ declare होती हैं उसे Abstract Class कहते हैं. इसके पास abstract और non-abstract methods हो सकती हैं. किसी सामान्य class के पास abstract methods नहीं होती है.

  • abstract class को हमेशा abstract keyword के साथ declare करना जरुरी होता है.
  • इसके पास abstract और non-abstract methods हो सकती है.
  • इसे instantiate नहीं किया जा सकता अर्थात् इसका प्रयोग objects को create करने के लिए नहीं कर सकते.
  • इसके पास constructors और static methods भी हो सकते हैं.
  • abstract class को use करने के लिए, हमें इसे दूसरी class से inherit करना होगा और abstract methods को implementation प्रदान करनी होगी.
  • इसके पास final methods भी हो सकती हैं.
  • abstract methods के पास body नहीं होती है.


Abstraction in Java :

Abstraction एक प्रक्रिया है जिसमें implementation को छुपा दिया जाता है और user को केवल functionality को ही show किया जाता है.
दूसरे शब्दों में कहें तो, “यह user को केवल आवश्यक जानकारी ही show करता है और जो background की details होती हैं उन्हें hide कर दिया जाता है.”

उदाहरण के लिए:- हम whatsapp में message को type करते है और उसे send कर देते है. लेकिन हमें उसकी internal working के बारें में पता नहीं होता कि message कैसे send होता है.

java में abstraction को प्राप्त करने के दो तरीके होते हैं:-

  • Abstract class
  • Interface


Abstract method क्या होती है?

वह मेथड जो abstract keyword के द्वारा declare होती है उसे abstract method कहते है. इस मेथड के पास implementation नहीं होता है अर्थात् इसके पास body नहीं होती.

  • इसमें abstract कीवर्ड को method name के आगे लिखा जाता है.
  • एक abstract मेथड एक method signature को contain करती है परन्तु इसमें body नहीं होती.
  • curly braces के बजाय, इस method के अंत में semicolon ; लगा होता है.

Syntax for abstract method :

abstract return_type method_name();   //abstract method

Java में देखे तो virtual नाम का कोई keyword नहीं होता, लेकिन Abstract Class का इस्तेमाल Java में भी abstract keyword के साथ किया जाता है |

Abstract class को abstract keyword के साथ लिखा जाता है |

Syntax for abstract method :

abstract class class_name();   //abstract class

Java - Abstract Classes using Multilevel Inheritance :

जब abstract super class के method की definition दी जाती तो super class का sub class भी abstract class हो जाता है |

एक abstract class में कितने भी abstract methods दिए जा सकते है | ये जरुरी नहीं है कि, हर abstract class के अन्दर abstract method हो |

Program पर class A इस abstract parent class में दो abstract methods दिए गए है | लेकिन उन दोनों abstract methods की definition उसे inherit किये गए sub-class पर की जाती है | उन दोनों abstract class का implementation करना जरुरी है |

Program पर Source Code ये है कि class A पर दो abstract methods दिए गए है और class B(sub-class) पर उसके सिर्फ एक ही abstract method का implementation किया गया है | इससे वो भी class abstract class हो जाती है |

Source Code :

abstract class A{           //Abstract Class  
	abstract void disp1();
	abstract void disp2();
	
}  
abstract class B extends A{    //Abstract Class
	void disp2(){
		System.out.println("class B");
	}
}
abstract class C extends B{   //Abstract Class
	void disp3(){
		System.out.println("class C"); //
	}
}
class D extends C{
	void disp1(){
		System.out.println("class D"); //
	}
	public static void main(String args[]){  
	
	D d = new D();
	d.disp1();
	d.disp2();
	d.disp3();
	}  
}

Output :

class D
class B
class C



अगर आपको यह पोस्ट 📑 पसंद आई हो तो अपने मित्रों के साथ जरूर शेयर करें। धन्यवाद !
Maxon

Hello there! I'm Maxon, a dedicated UI/UX designer on a mission to transform digital experiences into intuitive, user-centric journeys. With a keen eye for detail and a passion for crafting aesthetically pleasing interfaces, I strive to create designs that not only look stunning but also enhance usability and functionality.

Post a Comment

Previous Post Next Post