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
316
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.
व्याख्या (हिन्दी) संकलन-समय बहुरूपता में फ़ंक्शन ओवरलोडिंग और टेम्पलेट शामिल हैं - कंपाइलर द्वारा हल किया गया, कोई रनटाइम ओवरहेड नहीं।
317
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. आउटपुट: बी.सी.
318
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.
व्याख्या (हिन्दी) आरटीटीआई रनटाइम पर डायनामिक_कास्ट और टाइपआईडी के माध्यम से किसी ऑब्जेक्ट के प्रकार को क्वेरी करने की अनुमति देता है।
319
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.
320
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() देता है। आउटपुट: बी.
321
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.
व्याख्या (हिन्दी) सीआरटीपी (क्यूरियसली रिकरिंग टेम्प्लेट पैटर्न) वर्चुअल फ़ंक्शन ओवरहेड के बिना बहुरूपता प्राप्त करता है।
322
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.
व्याख्या (हिन्दी) कॉल ए को मान के आधार पर लेती है - स्लाइसिंग होती है, बी का एफ ओवरराइड खो जाता है। कॉल(बी) ए::एफ() को आमंत्रित करता है। आउटपुट: ए.
323
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.
324
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.
व्याख्या (हिन्दी) किसी भी फ़ंक्शन (वर्चुअल सहित) को शून्य पॉइंटर पर कॉल करना अपरिभाषित व्यवहार है।
325
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.
व्याख्या (हिन्दी) बी और सी दोनों एफ() को ओवरराइड करते हैं, जिससे डी के लिए अस्पष्टता पैदा होती है। डी को एफ() को ओवरराइड करना होगा या स्पष्ट रूप से अर्हता प्राप्त करनी होगी। संकलन त्रुटि.
326
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) का अमूर्त वर्ग में कोई कार्यान्वयन नहीं होता है और इसे ठोस व्युत्पन्न वर्गों में ओवरराइड किया जाना चाहिए।
327
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<'A';}}; class B:public A{public: void f()final{cout<<'B';}}; class C:public B{public: void f(){cout<<'C';}}; A*p=new C; p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
A
B
B बी
C
C सी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f() is final; C cannot override it. Compile error.
व्याख्या (हिन्दी) B::f() अंतिम है; C इसे ओवरराइड नहीं कर सकता. संकलन त्रुटि.
328
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<1;} virtual void f(int){cout<<2;}}; class B:public A{public: void f()override{cout<<3;}}; B b; b.f(5);
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
2 2
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f() hides all A::f overloads (name hiding). b.f(5) cannot find f(int) in B without using declaration. Compile error.
व्याख्या (हिन्दी) B::f() hides all A::f overloads (name hiding). b.f(5) घोषणा का उपयोग किए बिना B में f(int) नहीं ढूंढ सकता। संकलन त्रुटि.
329
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<'A';} ~A()=default;}; class B:public A{}; B b; b.f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
A
B
B बी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B does not override f(), so A::f() is inherited. b.f() calls A::f(). Output: A.
व्याख्या (हिन्दी) B, f() को ओवरराइड नहीं करता है, इसलिए A::f() विरासत में मिला है। b.f() A::f() को कॉल करता है। आउटपुट: ए.
330
EN + हिं
GB What is 'function hiding' in C++?
IN C++ में 'फंक्शन हिडिंग' क्या है?
A
Derived class function with same name hides all base class overloads समान नाम वाला व्युत्पन्न क्लास फ़ंक्शन सभी बेस क्लास ओवरलोड को छुपाता है
B
Virtual function override वर्चुअल फ़ंक्शन ओवरराइड
C
Private function access निजी फ़ंक्शन पहुंच
D
Function deletion फ़ंक्शन विलोपन
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Name hiding: if a derived class declares a function with the same name as base (even different signature), all base overloads are hidden.
व्याख्या (हिन्दी) नाम छिपाना: यदि कोई व्युत्पन्न वर्ग किसी फ़ंक्शन को आधार के समान नाम (यहां तक ​​​​कि अलग हस्ताक्षर) के साथ घोषित करता है, तो सभी आधार ओवरलोड छुपाए जाते हैं।
316–330 of 1915