Which of the following can be considered as the members that can be inherited…
2023
Which of the following can be considered as the members that can be inherited but not accessible in any class?
- A.
Public
- B.
Protected
- C.
Private
- D.
More than one of the above
- E.
None of the above
Attempted by 371 students.
Show answer & explanation
Correct answer: C
In object-oriented programming, when a class inherits from another class, the access specifiers determine the visibility of members in the derived class.
Public members are accessible from any class, including derived classes. Protected members are accessible within the derived class. However, private members are not directly accessible in the derived class, even though they are inherited.
Thus, private members are inheritable but not directly accessible in any derived class, making them the correct choice.
हिन्दी उत्तर:
वस्तु-निर्देशित प्रोग्रामिंग में, जब एक क्लास दूसरी क्लास से विरासत लेती है, तो एक्सेस स्पेसिफायर्स सदस्यों की दृश्यता निर्धारित करते हैं।
पब्लिक सदस्य किसी भी क्लास से एक्सेस किए जा सकते हैं, जिसमें व्युत्पन्न क्लास भी शामिल है। प्रोटेक्टेड सदस्य व्युत्पन्न क्लास में एक्सेस किए जा सकते हैं। हालांकि, प्राइवेट सदस्य व्युत्पन्न क्लास में सीधे एक्सेस नहीं किए जा सकते हैं, भले ही वे विरासत में लिए जाएं।
इसलिए, प्राइवेट सदस्य विरासत में लिए जा सकते हैं लेकिन किसी भी व्युत्पन्न क्लास में सीधे एक्सेस नहीं किए जा सकते हैं, जिससे वे सही विकल्प बन जाते हैं।