OOP Using C++ — MCQ Practice

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

📚 94 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
94 questions
1
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 का उपयोग करता है: वास्तविक ऑब्जेक्ट प्रकार के आधार पर रनटाइम पर सही फ़ंक्शन का चयन किया जाता है।
2
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.
3
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 होता है जो उसकी व्यवहार्यता की ओर इंगित करता है।
4
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.
5
EN + हिं
GB What is 'compile-time polymorphism'?
IN 'संकलन-समय बहुरूपता' क्या है?
A
Templates and function overloading टेम्प्लेट और फ़ंक्शन ओवरलोडिंग
B
Virtual functions आभासी कार्य
C
RTTI आरटीटीआई
D
Dynamic dispatch गतिशील प्रेषण
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Compile-time polymorphism includes function overloading and templates — resolved by compiler, no runtime overhead.
व्याख्या (हिन्दी) संकलन-समय बहुरूपता में फ़ंक्शन ओवरलोडिंग और टेम्पलेट शामिल हैं - कंपाइलर द्वारा हल किया गया, कोई रनटाइम ओवरहेड नहीं।
6
EN + हिं
GB What is the output: class A{public: virtual void f()=0;}; class B:public A{public: void f(){cout<<'B';}}; class C:public A{public: void f(){cout<<'C';}}; A*p[2]={new B,new C}; for(auto x:p) x->f();
IN आउटपुट क्या है: क्लास ए{सार्वजनिक: वर्चुअल शून्य f()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() {काउट
A
BC ईसा पूर्व
B
CB सीबी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p[0] is B, f()=B; p[1] is C, f()=C. Output: BC.
व्याख्या (हिन्दी) p[0] B है, f()=B; p[1] C है, f()=C. आउटपुट: बी.सी.
7
EN + हिं
GB What is RTTI in C++?
IN C++ में RTTI क्या है?
A
Run-Time Type Information — dynamic_cast and typeid रन-टाइम प्रकार की जानकारी - डायनामिक_कास्ट और टाइपिड
B
Runtime Template Instantiation रनटाइम टेम्प्लेट इंस्टेंटिएशन
C
Reference Type Tracking Interface संदर्भ प्रकार ट्रैकिंग इंटरफ़ेस
D
Recursive Type Tree Inspection पुनरावर्ती प्रकार वृक्ष निरीक्षण
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) RTTI allows querying the type of an object at runtime via dynamic_cast and typeid.
व्याख्या (हिन्दी) आरटीटीआई रनटाइम पर डायनामिक_कास्ट और टाइपआईडी के माध्यम से किसी ऑब्जेक्ट के प्रकार को क्वेरी करने की अनुमति देता है।
8
EN + हिं
GB What is 'dynamic_cast' used for?
IN 'डायनामिक_कास्ट' का उपयोग किसके लिए किया जाता है?
A
Safe downcasting of polymorphic types बहुरूपी प्रकारों का सुरक्षित डाउनकास्टिंग
B
Casting between unrelated types असंबंधित प्रकारों के बीच कास्टिंग
C
Const removal स्थिरांक हटाना
D
Pointer arithmetic सूचक अंकगणित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) dynamic_cast safely casts to derived type; returns nullptr (for pointers) or throws std::bad_cast (for references) if cast fails.
व्याख्या (हिन्दी) डायनामिक_कास्ट सुरक्षित रूप से व्युत्पन्न प्रकार में बदल जाता है; returns nullptr (for pointers) or throws std::bad_cast (for references) if cast fails.
9
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<'A';} void g(){f();}}; class B:public A{public: void f()override{cout<<'B';}}; B b; b.g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
A
B
B बी
C
AB अब
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() calls f() via this->f(); virtual dispatch gives B::f(). Output: B.
व्याख्या (हिन्दी) g() इस->f() के माध्यम से f() को कॉल करता है; आभासी प्रेषण B::f() देता है। आउटपुट: बी.
10
EN + हिं
GB What is 'static polymorphism' via templates?
IN टेम्प्लेट के माध्यम से 'स्थैतिक बहुरूपता' क्या है?
A
CRTP — behavior customized at compile time via template parameter सीआरटीपी - टेम्पलेट पैरामीटर के माध्यम से संकलन समय पर अनुकूलित व्यवहार
B
Virtual functions without vtable वीटेबल के बिना आभासी कार्य
C
Runtime dispatch via templates टेम्प्लेट के माध्यम से रनटाइम प्रेषण
D
Function overloading only केवल फ़ंक्शन ओवरलोडिंग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) CRTP (Curiously Recurring Template Pattern) achieves polymorphism without virtual function overhead.
व्याख्या (हिन्दी) सीआरटीपी (क्यूरियसली रिकरिंग टेम्प्लेट पैटर्न) वर्चुअल फ़ंक्शन ओवरहेड के बिना बहुरूपता प्राप्त करता है।
11
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<'A';} virtual ~A(){}}; class B:public A{public: void f()override{cout<<'B';}}; void call(A a){a.f();} B b; call(b);
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
A
B
B बी
C
AB अब
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) call takes A by value — slicing occurs, B's f override is lost. call(b) invokes A::f(). Output: A.
व्याख्या (हिन्दी) कॉल ए को मान के आधार पर लेती है - स्लाइसिंग होती है, बी का एफ ओवरराइड खो जाता है। कॉल(बी) ए::एफ() को आमंत्रित करता है। आउटपुट: ए.
12
EN + हिं
GB What is the output: class A{public: virtual int f(){return 10;} int g(){return f()*2;}}; class B:public A{public: int f()override{return 20;}}; B b; cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: वर्चुअल int f() {रिटर्न 10;} int g() {रिटर्न f()*2;}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: int f() ओवरराइड {वापसी 20;}}; बी बी; अदालत
A
20 20
B
40 40
C
10 10
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b.g() calls A::g() (not overridden). A::g() calls f(), which is virtual: dispatches to B::f()=20. g()=20*2=40.
व्याख्या (हिन्दी) b.g() calls A::g() (not overridden). A::g() f() को कॉल करता है, जो वर्चुअल है: B::f()=20 को भेजता है। जी()=20*2=40.
13
EN + हिं
GB What happens when you call a virtual function on a null pointer?
IN जब आप किसी वर्चुअल फ़ंक्शन को शून्य पॉइंटर पर कॉल करते हैं तो क्या होता है?
A
Calls base implementation आधार कार्यान्वयन को कॉल करता है
B
Undefined behavior अपरिभाषित व्यवहार
C
Runtime exception क्रम अपवाद
D
Null returned शून्य वापस आ गया
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Calling any function (including virtual) on a null pointer is undefined behavior.
व्याख्या (हिन्दी) किसी भी फ़ंक्शन (वर्चुअल सहित) को शून्य पॉइंटर पर कॉल करना अपरिभाषित व्यवहार है।
14
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<1;}}; class B:public virtual A{public: void f(){cout<<2;}}; class C:public virtual A{public: void f(){cout<<3;}}; class D:public B,public C{}; D d; d.f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
2 2
B
3 3
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Both B and C override f(), creating ambiguity for D. D must override f() or explicitly qualify. Compile error.
व्याख्या (हिन्दी) बी और सी दोनों एफ() को ओवरराइड करते हैं, जिससे डी के लिए अस्पष्टता पैदा होती है। डी को एफ() को ओवरराइड करना होगा या स्पष्ट रूप से अर्हता प्राप्त करनी होगी। संकलन त्रुटि.
15
EN + हिं
GB What is 'pure virtual function'?
IN 'शुद्ध वर्चुअल फ़ंक्शन' क्या है?
A
virtual void f()=0 — must be overridden in derived class वर्चुअल शून्य f()=0 - व्युत्पन्न वर्ग में ओवरराइड किया जाना चाहिए
B
Virtual function with empty body खाली बॉडी के साथ वर्चुअल फ़ंक्शन
C
Function that calls base फ़ंक्शन जो आधार को कॉल करता है
D
Inline virtual function इनलाइन वर्चुअल फ़ंक्शन
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A pure virtual function (=0) has no implementation in the abstract class and must be overridden in concrete derived classes.
व्याख्या (हिन्दी) एक शुद्ध वर्चुअल फ़ंक्शन (=0) का अमूर्त वर्ग में कोई कार्यान्वयन नहीं होता है और इसे ठोस व्युत्पन्न वर्गों में ओवरराइड किया जाना चाहिए।
1–15 of 94