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
301
EN + हिं
GB What is the output: class A{int x=1; public: int get(){return x;}}; class B:private A{public: int f(){return get();}}; B b; cout<
IN आउटपुट क्या है: class A{int x=1; सार्वजनिक: int get(){return x;}}; कक्षा बी: निजी ए {सार्वजनिक: int f() {वापसी प्राप्त();}}; बी बी; अदालत
A
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f() inside B can call get() (accessible via private inheritance). f()=get()=1. Output: 1.
व्याख्या (हिन्दी) B के अंदर f() get() (निजी विरासत के माध्यम से पहुंच योग्य) को कॉल कर सकता है। f()=प्राप्त()=1. आउटपुट: 1.
302
EN + हिं
GB What is the output: class A{public: void f(){cout<<'A';}}; class B:public A{using A::f; public: void f(int x){cout<<'B';}}; B b; b.f();
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: शून्य एफ() {काउट
A
A
B
B बी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) using A::f brings A::f into B's scope. b.f() with no args calls A::f. Output: A.
व्याख्या (हिन्दी) A::f का उपयोग करने से A::f B के दायरे में आ जाता है। b.f() बिना किसी तर्क के A::f कॉल करता है। आउटपुट: ए.
303
EN + हिं
GB What is 'interface' in C++ (no interface keyword)?
IN C++ में 'इंटरफ़ेस' क्या है (कोई इंटरफ़ेस कीवर्ड नहीं)?
A
Abstract class with only pure virtual functions केवल शुद्ध आभासी कार्यों के साथ सार वर्ग
B
A header file एक हेडर फ़ाइल
C
A template class एक टेम्पलेट क्लास
D
A concept (C++20) एक अवधारणा (C++20)
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Interfaces in C++ are simulated using abstract classes with only pure virtual functions and no data members.
व्याख्या (हिन्दी) C++ में इंटरफ़ेस केवल शुद्ध वर्चुअल फ़ंक्शंस और बिना किसी डेटा सदस्य के अमूर्त वर्गों का उपयोग करके सिम्युलेटेड होते हैं।
304
EN + हिं
GB What is the output: class A{public: int x=5;}; class B:public A{}; class C:public A{}; class D:public B,public C{}; D d; cout<
IN आउटपुट क्या है: class A{public: int x=5;}; कक्षा बी:सार्वजनिक ए{}; कक्षा सी:सार्वजनिक ए{}; कक्षा डी:सार्वजनिक बी,सार्वजनिक सी{}; डी डी; अदालत
A
5 5
B
Compile error संकलन त्रुटि
C
Ambiguous अस्पष्ट
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) d.B::x explicitly accesses B's copy of A::x = 5. Output: 5.
व्याख्या (हिन्दी) d.B::x स्पष्ट रूप से B की A::x = 5 की प्रतिलिपि तक पहुँचता है। आउटपुट: 5।
305
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<'A';} virtual void g(){cout<<'G';}}; class B:public A{public: void f()override{cout<<'B';}}; A*p=new B; p->g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
G जी
B
A
C
B बी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B does not override g(), so A::g() is called via vtable. Output: G.
व्याख्या (हिन्दी) B, g() को ओवरराइड नहीं करता है, इसलिए A::g() को vtable के माध्यम से कॉल किया जाता है। आउटपुट: जी.
306
EN + हिं
GB What is 'protected constructor'?
IN 'संरक्षित कंस्ट्रक्टर' क्या है?
A
Constructor callable only from derived classes कंस्ट्रक्टर केवल व्युत्पन्न कक्षाओं से कॉल करने योग्य है
B
Private constructor निजी निर्माणकर्ता
C
Virtual constructor वर्चुअल कंस्ट्रक्टर
D
Default constructor डिफ़ॉल्ट कंस्ट्रक्टर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A protected constructor prevents direct instantiation but allows derived class constructors to call it.
व्याख्या (हिन्दी) एक संरक्षित कंस्ट्रक्टर प्रत्यक्ष इंस्टेंशियेशन को रोकता है लेकिन व्युत्पन्न क्लास कंस्ट्रक्टर्स को इसे कॉल करने की अनुमति देता है।
307
EN + हिं
GB What is the output: class A{public: int f(){return 1;}}; class B:public A{public: int f(){return 2;}}; A a=B(); cout<
IN आउटपुट क्या है: कक्षा ए {सार्वजनिक: int f() {वापसी 1;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक: int f(){वापसी 2;}}; ए ए=बी(); अदालत
A
1 1
B
2 2
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Object slicing: B() is sliced to A when assigned to a. a.f() calls A::f()=1. Output: 1.
व्याख्या (हिन्दी) ऑब्जेक्ट स्लाइसिंग: जब ए को सौंपा जाता है तो बी() को ए में स्लाइस किया जाता है। a.f() A::f()=1 को कॉल करता है। आउटपुट: 1.
308
EN + हिं
GB What is 'EBO' (Empty Base Optimization)?
IN 'ईबीओ' (खाली आधार अनुकूलन) क्या है?
A
Empty base class occupies no space in derived class खाली आधार वर्ग व्युत्पन्न वर्ग में कोई स्थान नहीं घेरता
B
Optimization for virtual functions आभासी कार्यों के लिए अनुकूलन
C
Base class inlining बेस क्लास इनलाइनिंग
D
Eliminating base constructors आधार निर्माणकर्ताओं को हटाना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) EBO allows the compiler to give empty base classes zero size when used as a base, optimizing memory.
व्याख्या (हिन्दी) ईबीओ कंपाइलर को मेमोरी को अनुकूलित करते हुए, आधार के रूप में उपयोग किए जाने पर खाली बेस क्लास को शून्य आकार देने की अनुमति देता है।
309
EN + हिं
GB What is the output: class A{public: void f(){cout<<1;} virtual void g(){cout<<2;}}; class B:public A{public: void f(){cout<<3;} void g()override{cout<<4;}}; B b; A&r=b; r.f(); r.g();
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: शून्य एफ() {काउट
A
12 12
B
13 13
C
14 14
D
34 34
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) r.f(): f is non-virtual, static dispatch, calls A::f()=1. r.g(): g is virtual, dynamic dispatch, calls B::g()=4. Output: 14.
व्याख्या (हिन्दी) r.f(): f गैर-आभासी, स्थिर प्रेषण है, A::f()=1 को कॉल करता है। r.g(): g आभासी, गतिशील प्रेषण है, B::g()=4 को कॉल करता है। आउटपुट: 14.
310
EN + हिं
GB What is the output: class A{public: A(){cout<<'A';} virtual ~A(){cout<<'a';}}; class B:public A{public: B(){cout<<'B';} ~B(){cout<<'b';}}; B b;
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
ABba एबीबीए
B
AaBb आब
C
ABab अबाब
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Construct: A (prints A), B (prints B). Destruct: ~B (prints b), ~A (prints a). Output: ABba.
व्याख्या (हिन्दी) निर्माण: ए (प्रिंट ए), बी (प्रिंट बी)। नष्ट करें: ~बी (बी प्रिंट करता है), ~ए (ए प्रिंट करता है)। आउटपुट: एबीबीए.
311
EN + हिं
GB What is 'using declaration' in derived class context?
IN व्युत्पन्न वर्ग संदर्भ में 'घोषणा का उपयोग' क्या है?
A
Brings base class member into derived class scope बेस क्लास सदस्य को व्युत्पन्न क्लास स्कोप में लाता है
B
Using namespace alias नेमस्पेस उपनाम का उपयोग करना
C
Type alias उपनाम टाइप करें
D
Forward declaration अग्रेषित घोषणा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) using Base::memberName in derived class makes the member accessible under derived class name and affects overload resolution.
व्याख्या (हिन्दी) व्युत्पन्न वर्ग में Base::memberName का उपयोग करने से सदस्य व्युत्पन्न वर्ग नाम के तहत पहुंच योग्य हो जाता है और ओवरलोड रिज़ॉल्यूशन को प्रभावित करता है।
312
EN + हिं
GB What is 'runtime polymorphism' in C++?
IN C++ में 'रनटाइम बहुरूपता' क्या है?
A
Virtual function dispatch resolved at compile time वर्चुअल फ़ंक्शन प्रेषण संकलन समय पर हल हो गया
B
Virtual function dispatch resolved at runtime via vtable वर्चुअल फ़ंक्शन डिस्पैच को vtable के माध्यम से रनटाइम पर हल किया गया
C
Template specialization टेम्पलेट विशेषज्ञता
D
Function overloading फ़ंक्शन ओवरलोडिंग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Runtime polymorphism uses vtables: the correct function is selected at runtime based on the actual object type.
व्याख्या (हिन्दी) रनटाइम बहुरूपता vtables का उपयोग करता है: वास्तविक ऑब्जेक्ट प्रकार के आधार पर रनटाइम पर सही फ़ंक्शन का चयन किया जाता है।
313
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<1;}}; class B:public A{public: void f()override{cout<<2;}}; void call(A&a){a.f();} B b; call(b);
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
1 1
B
2 2
C
12 12
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.f() with virtual dispatch calls B::f()=2 when b is passed. Output: 2.
व्याख्या (हिन्दी) a.f() with virtual dispatch calls B::f()=2 when b is passed. आउटपुट: 2.
314
EN + हिं
GB What is a 'vtable'?
IN 'वीटेबल' क्या है?
A
Compiler-generated table of virtual function pointers वर्चुअल फ़ंक्शन पॉइंटर्स की कंपाइलर-जनरेटेड तालिका
B
Variable table परिवर्तनीय तालिका
C
Virtual template आभासी टेम्पलेट
D
Value table मूल्य तालिका
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) The vtable (virtual dispatch table) stores pointers to the virtual functions of a class; each polymorphic object has a vptr pointing to its vtable.
व्याख्या (हिन्दी) वीटेबल (वर्चुअल डिस्पैच टेबल) किसी क्लास के वर्चुअल फ़ंक्शंस के पॉइंटर्स को संग्रहीत करता है; प्रत्येक बहुरूपी वस्तु में एक vptr होता है जो उसकी व्यवहार्यता की ओर इंगित करता है।
315
EN + हिं
GB What is the output: class A{public: virtual int f(){return 1;}}; class B:public A{public: int f()override{return 2;}}; class C:public B{public: int f()override{return 3;}}; A*p=new C; cout<f();
IN What is the output: class A{public: virtual int f(){return 1;}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: int f() ओवरराइड {वापसी 2;}}; कक्षा सी:सार्वजनिक बी{सार्वजनिक: int f()ओवरराइड{वापसी 3;}}; A*p=new C; अदालत
A
1 1
B
2 2
C
3 3
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f() dispatches to C::f() (most derived override). Output: 3.
व्याख्या (हिन्दी) p->f() C::f() (सबसे व्युत्पन्न ओवरराइड) को भेजता है। आउटपुट: 3.
301–315 of 1915