Which type of method does not have an implementation in the base class and…
2025
Which type of method does not have an implementation in the base class and must be overridden by derived classes?
- A.
Virtual method
- B.
Abstract method
- C.
Sealed method
- D.
Static method
Attempted by 810 students.
Show answer & explanation
Correct answer: B
In object-oriented programming, different types of methods behave differently in inheritance. Let's analyze each option:
A virtual method has an implementation in the base class and can be overridden in derived classes. It is not required to override it, but it can be.
An abstract method does not have an implementation in the base class. It is declared with the 'abstract' keyword and must be implemented (overridden) by any non-abstract derived class.
A sealed method cannot be overridden in derived classes. It is used to prevent further inheritance of a method.
A static method belongs to the class itself, not to instances, and cannot be overridden in derived classes.
Therefore, the method that does not have an implementation in the base class and must be overridden by derived classes is the abstract method.
हिन्दी उत्तर:
ऑब्जेक्ट-ओरिएंटेड प्रोग्रामिंग में, विभिन्न प्रकार के मेथड विरासत में अलग-अलग तरीके से व्यवहार करते हैं। आइए प्रत्येक विकल्प का विश्लेषण करें:
एक वर्चुअल मेथड के पास बेस क्लास में एक इम्प्लीमेंटेशन होता है और डेराइव्ड क्लास में ओवरराइड किया जा सकता है। इसे ओवरराइड करना आवश्यक नहीं है, लेकिन यह संभव है।
एक एब्स्ट्रैक्ट मेथड के पास बेस क्लास में इम्प्लीमेंटेशन नहीं होता है। इसे 'एब्स्ट्रैक्ट' कीवर्ड के साथ घोषित किया जाता है और किसी भी गैर-एब्स्ट्रैक्ट डेराइव्ड क्लास द्वारा इम्प्लीमेंट (ओवरराइड) किया जाना चाहिए।
एक सील्ड मेथड को डेराइव्ड क्लास में ओवरराइड नहीं किया जा सकता है। इसका उपयोग एक मेथड के आगे विरासत को रोकने के लिए किया जाता है।
एक स्टैटिक मेथड क्लास के लिए होता है, इंस्टेंस के लिए नहीं, और डेराइव्ड क्लास में ओवरराइड नहीं किया जा सकता है।
इसलिए, वह मेथड जिसके पास बेस क्लास में इम्प्लीमेंटेशन नहीं होता है और जिसे डेराइव्ड क्लास द्वारा ओवरराइड करना आवश्यक होता है, वह एब्स्ट्रैक्ट मेथड है।