OOP Using C++ — MCQ Practice

Hindi aur English dono mein practice karo — click karo answer check karne ke liye

📚 1915 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
1915 questions
226
EN + हिं
GB What is the output: class A{public: int x; A(int v):x(v){} A(const A& a):x(a.x+1){}}; A a(5); A b=a; cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; A(int v):x(v){} A(const A& a):x(a.x+1){}}; ए ए(5); ए बी=ए; अदालत
A
5 5
B
6 6
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Copy constructor called: b.x = a.x+1 = 6. Output: 6.
व्याख्या (हिन्दी) कॉपी कंस्ट्रक्टर कहा जाता है: b.x = a.x+1 = 6. आउटपुट: 6.
227
EN + हिं
GB What is 'object slicing' in C++?
IN C++ में 'ऑब्जेक्ट स्लाइसिंग' क्या है?
A
Derived object assigned to base: derived part lost व्युत्पन्न वस्तु को आधार सौंपा गया: व्युत्पन्न भाग खो गया
B
Virtual function optimization वर्चुअल फ़ंक्शन अनुकूलन
C
Memory fragmentation स्मृति विखंडन
D
Partial initialization आंशिक आरंभीकरण
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) When a derived class object is assigned to a base class object (by value), the derived-specific members are sliced off.
व्याख्या (हिन्दी) जब एक व्युत्पन्न वर्ग ऑब्जेक्ट को बेस क्लास ऑब्जेक्ट (मूल्य के आधार पर) सौंपा जाता है, तो व्युत्पन्न-विशिष्ट सदस्यों को काट दिया जाता है।
228
EN + हिं
GB What is the output: class A{public: int x=0; void f(){x++;}}; A a,b; a.f(); cout<
IN आउटपुट क्या है: class A{public: int x=0; शून्य f(){x++;}}; ए ए, बी; a.f(); अदालत
A
10 10
B
11 11
C
00 00
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a and b are separate instances. a.f() increments a.x to 1. b.x unchanged=0. Output: 10.
व्याख्या (हिन्दी) ए और बी अलग-अलग उदाहरण हैं। a.f() a.x को 1 तक बढ़ाता है। b.x अपरिवर्तित=0। आउटपुट: 10.
229
EN + हिं
GB What is 'operator overloading'?
IN 'ऑपरेटर ओवरलोडिंग' क्या है?
A
Defining operator behavior for user-defined types उपयोगकर्ता-परिभाषित प्रकारों के लिए ऑपरेटर व्यवहार को परिभाषित करना
B
Overriding operators at runtime रनटाइम पर ओवरराइडिंग ऑपरेटर
C
Removing standard operators मानक ऑपरेटरों को हटाना
D
Calling multiple operators एकाधिक ऑपरेटरों को कॉल करना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Operator overloading allows defining how operators work with user-defined classes.
व्याख्या (हिन्दी) ऑपरेटर ओवरलोडिंग यह परिभाषित करने की अनुमति देता है कि ऑपरेटर उपयोगकर्ता-परिभाषित कक्षाओं के साथ कैसे काम करते हैं।
230
EN + हिं
GB What is the output: class A{public: A(){cout<<'C';} ~A(){cout<<'D';}}; {A a;}
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
C सी
B
D डी
C
CD सीडी
D
DC डीसी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Constructor prints C, then when block exits, destructor prints D. Output: CD.
व्याख्या (हिन्दी) कंस्ट्रक्टर सी प्रिंट करता है, फिर जब ब्लॉक बाहर निकलता है, तो डिस्ट्रक्टर डी प्रिंट करता है। आउटपुट: सीडी।
231
EN + हिं
GB What is a 'copy constructor'?
IN 'कॉपी कंस्ट्रक्टर' क्या है?
A
Constructor taking const reference to same class कंस्ट्रक्टर उसी क्लास का कॉन्स्ट रेफरेंस ले रहा है
B
Constructor for arrays सरणियों के लिए कंस्ट्रक्टर
C
Default constructor डिफ़ॉल्ट कंस्ट्रक्टर
D
Move constructor कंस्ट्रक्टर को स्थानांतरित करें
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Copy constructor: A(const A& other) — initializes a new object as a copy of another.
व्याख्या (हिन्दी) कॉपी कंस्ट्रक्टर: ए (कॉन्स्ट ए और अन्य) - एक नई वस्तु को दूसरे की प्रतिलिपि के रूप में प्रारंभ करता है।
232
EN + हिं
GB What is 'Rule of Three' in C++?
IN C++ में 'तीन का नियम' क्या है?
A
If you define destructor/copy-ctor/copy-assign, define all three यदि आप डिस्ट्रक्टर/कॉपी-क्टर/कॉपी-असाइन को परिभाषित करते हैं, तो तीनों को परिभाषित करें
B
Three constructors per class प्रति कक्षा तीन कंस्ट्रक्टर
C
Three virtual functions तीन आभासी कार्य
D
Three inheritance levels तीन वंशानुक्रम स्तर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) If a class needs a user-defined destructor, copy constructor, or copy assignment, it likely needs all three.
व्याख्या (हिन्दी) यदि किसी वर्ग को उपयोगकर्ता-परिभाषित डिस्ट्रक्टर, कॉपी कंस्ट्रक्टर, या कॉपी असाइनमेंट की आवश्यकता होती है, तो उसे संभवतः इन तीनों की आवश्यकता होती है।
233
EN + हिं
GB What is the output: class A{public: int x; A():x(0){} A(int v):x(v){}}; A a; cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; A():x(0){} A(int v):x(v){}}; ए ए; अदालत
B
1 1
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A a uses default constructor A():x(0). Output: 0.
व्याख्या (हिन्दी) A डिफ़ॉल्ट कंस्ट्रक्टर A():x(0) का उपयोग करता है। आउटपुट: 0.
234
EN + हिं
GB What is 'mutable' keyword for class members?
IN कक्षा सदस्यों के लिए 'म्यूटेबल' कीवर्ड क्या है?
A
Allows member to be modified even in const member functions कॉन्स्ट सदस्य फ़ंक्शंस में भी सदस्य को संशोधित करने की अनुमति देता है
B
Makes member public सदस्य को सार्वजनिक बनाता है
C
Makes member static सदस्य को स्थिर बनाता है
D
Prevents copy नकल रोकता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) mutable allows a data member to be modified inside const member functions.
व्याख्या (हिन्दी) म्यूटेबल एक डेटा सदस्य को कॉन्स्ट सदस्य फ़ंक्शन के अंदर संशोधित करने की अनुमति देता है।
235
EN + हिं
GB What is the output: class A{public: operator int(){return 42;}}; A a; cout<<(int)a;
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: ऑपरेटर int() {रिटर्न 42;}}; ए ए; अदालत
A
42 42
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) User-defined conversion operator returns 42. (int)a calls it. Output: 42.
व्याख्या (हिन्दी) उपयोगकर्ता-परिभाषित रूपांतरण ऑपरेटर 42 लौटाता है। (int)a इसे कॉल करता है। आउटपुट: 42.
236
EN + हिं
GB What is 'aggregate initialization'?
IN 'समग्र आरंभीकरण' क्या है?
A
Initializing aggregate types with brace-enclosed list ब्रेस-संलग्न सूची के साथ समुच्चय प्रकारों को प्रारंभ करना
B
Initializing arrays only केवल आरंभिक सरणियाँ
C
Virtual class initialization वर्चुअल क्लास आरंभीकरण
D
Constructor with multiple params एकाधिक पैरामीटर वाला कंस्ट्रक्टर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Aggregates (classes with no user-defined constructors, etc.) can be initialized with {val1, val2, ...}.
व्याख्या (हिन्दी) एग्रीगेट्स (बिना उपयोगकर्ता-परिभाषित कंस्ट्रक्टर वाली कक्षाएं, आदि) को {val1, val2, ...} के साथ प्रारंभ किया जा सकता है।
237
EN + हिं
GB What is the output: class A{public: int x=10; int f() const {return x;}}; const A a; cout<
IN आउटपुट क्या है: class A{public: int x=10; int f() स्थिरांक {वापसी x;}}; स्थिरांक ए ए; अदालत
A
10 10
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) const object can only call const member functions. f() is const and returns x=10.
व्याख्या (हिन्दी) कॉन्स्ट ऑब्जेक्ट केवल कॉन्स्ट सदस्य फ़ंक्शंस को कॉल कर सकता है। f() स्थिरांक है और x=10 लौटाता है।
238
EN + हिं
GB What is 'explicit' constructor?
IN 'स्पष्ट' कंस्ट्रक्टर क्या है?
A
Prevents implicit conversion of constructor argument कंस्ट्रक्टर तर्क के अंतर्निहित रूपांतरण को रोकता है
B
Makes constructor public कंस्ट्रक्टर को सार्वजनिक बनाता है
C
Forces inline expansion इनलाइन विस्तार को बल देता है
D
Deletes copy constructor कॉपी कंस्ट्रक्टर को हटाता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) explicit prevents the constructor from being used in implicit conversions or copy-initialization.
व्याख्या (हिन्दी) स्पष्ट कन्स्ट्रक्टर को अंतर्निहित रूपांतरण या प्रतिलिपि-प्रारंभिकरण में उपयोग करने से रोकता है।
239
EN + हिं
GB What is the output: class A{public: static void f(){cout<<'S';} void g(){cout<<'G';}}; A::f(); A a; a.g();
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: स्थिर शून्य एफ() {काउट
A
SG एसजी
B
GS जी एस
C
Compile error संकलन त्रुटि
D
SS एसएस
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A::f() calls static f, prints S. a.g() calls instance g, prints G. Output: SG.
व्याख्या (हिन्दी) A::f() स्टेटिक f को कॉल करता है, S को प्रिंट करता है। a.g() इंस्टेंस g को कॉल करता है, G को प्रिंट करता है। आउटपुट: SG।
240
EN + हिं
GB What is the output: class A{public: int x; A(int v=0):x(v){}}; A a=5; cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; A(int v=0):x(v){}}; ए ए=5; अदालत
A
5 5
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A a=5 uses implicit conversion (copy-initialization): calls A(5), x=5. Output: 5.
व्याख्या (हिन्दी) A a=5 अंतर्निहित रूपांतरण (कॉपी-इनिशियलाइज़ेशन) का उपयोग करता है: A(5), x=5 को कॉल करता है। आउटपुट: 5.
226–240 of 1915