Choose true statements about virtual functions in C++: I: The virtual…
2022
Choose true statements about virtual functions in C++: I: The virtual functions must be member of some class. II: They cannot be static members. III: A virtual function can be a friend of another class.
Answer: D. I, II and III — Step 1: Virtual functions must be class members (I is correct). Step 2: They cannot be static (II is correct). Step 3: A virtual function can be a friend of…
- A.
I and II
- B.
II and III
- C.
I and III
- D.
I, II and III
Attempted by 205 students.
Show answer & explanation
Correct answer: D
Step 1: Virtual functions must be class members (I is correct).
Step 2: They cannot be static (II is correct).
Step 3: A virtual function can be a friend of another class (III is correct).
Step 4: All three statements are valid based on C++ rules.
I: वर्चुअल फलन किसी क्लास के सदस्य फलन होने ही चाहिए। यह सत्य है क्योंकि वर्चुअल फलन का डायनामिक बाइंडिंग क्लास के इन्स्टेंस के आधार पर होता है, जिसके लिए यह एक मेम्बर फलन होना आवश्यक है।
II: वे स्टेटिक सदस्य नहीं हो सकते। यह सत्य है क्योंकि स्टेटिक फलन का बाइंडिंग कंपाइल टाइम पर होता है और वर्चुअल फलन के लिए रनटाइम बाइंडिंग आवश्यक होती है।
III: एक वर्चुअल फलन अन्य क्लास का मित्र फलन हो सकता है। यह सत्य है क्योंकि फ्रेंड फलन की अनुमति एक क्लास के प्राइवेट या प्रोटेक्टेड मेम्बर्स को एक्सेस करने की होती है, और यह वर्चुअलिटी के साथ टकराता नहीं है।
इसलिए, सभी तीन कथन सत्य हैं।
हिन्दी उत्तर: वर्चुअल फलन के लिए ये तीनों कथन सत्य हैं।