Abstraction in Java जावा में एब्सट्रेक्शन, Abstract Class in Java जावा में एब्सट्रेक्ट क्लास
Abstraction in Java is a process of hiding unnecessary implementation details and showing only essential features of an object. It helps in focusing on what an object does rather than how it does it.
जावा में एब्सट्रेक्शन वह प्रक्रिया है जिसमें किसी वस्तु के केवल आवश्यक गुणों को प्रदर्शित किया जाता है और अनावश्यक विवरणों को छुपाया जाता है। इससे हम यह जान पाते हैं कि कोई वस्तु क्या करती है, न कि कैसे करती है।
Abstract Class in Java
An abstract class is declared using the abstract
keyword. It can contain both abstract methods (without body) and concrete methods (with body).
एब्सट्रेक्ट क्लास वह होती है जिसे abstract
कीवर्ड के साथ घोषित किया जाता है। इसमें सामान्य (concrete) और एब्सट्रेक्ट दोनों प्रकार की मेथड्स हो सकती हैं।
Abstract Method
abstract
keyword and ends with a semicolon ;
.एब्सट्रेक्ट मेथड वह होती है जिसमें बॉडी नहीं होती। इसे abstract
कीवर्ड के साथ घोषित किया जाता है और अंत में ;
से समाप्त किया जाता है। इसे सब-क्लास में ओवरराइड करना आवश्यक होता है।
Syntax:
abstract class ClassName {
abstract return_type methodName();return_type anotherMethod() {// Method body}}
Example:
abstract class Animal {
abstract void breath();void eat() {System.out.println("I am eating as Animal...");}}class Dog extends Animal {void breath() {System.out.println("Breathing as Dog...");}}class AbstractTest {public static void main(String args[]) {Dog d = new Dog();d.breath();d.eat();}}
Animal
is an abstract class. The method breath()
is abstract and is overridden in the Dog
class.Animal
एक एब्सट्रेक्ट क्लास है जिसमें breath()
एब्सट्रेक्ट मेथड है और इसे Dog
क्लास में ओवरराइड किया गया है।✅ Advantages of Abstraction in Java
-
Encourages code reuse. कोड के पुनः उपयोग को बढ़ावा देता है।
-
Maintains privacy and internal logic can be changed without affecting the user. प्रोग्राम की गोपनीयता बनाए रखता है और आंतरिक कोड को बिना यूज़र को बताए बदला जा सकता है।
-
Supports loose coupling between classes. लूज़ कपल्ड क्लास बनाने में सहायक होता है।
Comments
Post a Comment