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
16
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 इसे ओवरराइड नहीं कर सकता. संकलन त्रुटि.
17
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) नहीं ढूंढ सकता। संकलन त्रुटि.
18
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() को कॉल करता है। आउटपुट: ए.
19
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.
व्याख्या (हिन्दी) नाम छिपाना: यदि कोई व्युत्पन्न वर्ग किसी फ़ंक्शन को आधार के समान नाम (यहां तक ​​​​कि अलग हस्ताक्षर) के साथ घोषित करता है, तो सभी आधार ओवरलोड छुपाए जाते हैं।
20
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<'A';}}; class B:public A{public: virtual void f(){cout<<'B';}}; class C:public B{public: virtual void f(){cout<<'C';}}; A*p=new C; delete p;
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
UB: A's dtor called only यूबी: ए के डीटोर को ही बुलाया गया है
B
B,C dtors also called बी,सी डीटोर भी बुलाए गए
C
Compile error संकलन त्रुटि
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Without virtual destructor in A, deleting C through A* is undefined behavior; only A's destructor may be called.
व्याख्या (हिन्दी) ए में वर्चुअल डिस्ट्रक्टर के बिना, सी से ए* को हटाना अपरिभाषित व्यवहार है; केवल ए के विध्वंसक को ही बुलाया जा सकता है।
21
EN + हिं
GB What is typeid() used for?
IN टाइपआईडी() का उपयोग किसके लिए किया जाता है?
A
Getting runtime type information रनटाइम प्रकार की जानकारी प्राप्त करना
B
Type conversion रूपांतरण टाइप करें
C
sizeof alternative विकल्प का आकार
D
Template specialization trigger टेम्पलेट विशेषज्ञता ट्रिगर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) typeid(expr) returns a std::type_info object representing the runtime type; requires at least one virtual function for polymorphic types.
व्याख्या (हिन्दी) typeid(expr) रनटाइम प्रकार का प्रतिनिधित्व करने वाला एक std::type_info ऑब्जेक्ट लौटाता है; बहुरूपी प्रकारों के लिए कम से कम एक वर्चुअल फ़ंक्शन की आवश्यकता होती है।
22
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<1;}}; class B:public A{public: void f()override{cout<<2;}}; A *p=new B; static_cast(p)->A::f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
1 1
B
2 2
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Explicit A::f() bypasses virtual dispatch and calls A's version directly. Output: 1.
व्याख्या (हिन्दी) स्पष्ट A::f() वर्चुअल प्रेषण को बायपास करता है और सीधे A के संस्करण को कॉल करता है। आउटपुट: 1.
23
EN + हिं
GB What is 'open/closed principle' relation to polymorphism?
IN बहुरूपता से 'खुला/बंद सिद्धांत' क्या संबंध है?
A
Polymorphism enables extending behavior without modifying existing code बहुरूपता मौजूदा कोड को संशोधित किए बिना व्यवहार को विस्तारित करने में सक्षम बनाता है
B
Requires multiple inheritance एकाधिक वंशानुक्रम की आवश्यकता है
C
Template metaprogramming only केवल टेम्प्लेट मेटाप्रोग्रामिंग
D
Runtime type checking रनटाइम प्रकार की जाँच
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Polymorphism (especially virtual functions) supports the open/closed principle: open for extension, closed for modification.
व्याख्या (हिन्दी) बहुरूपता (विशेषकर आभासी कार्य) खुले/बंद सिद्धांत का समर्थन करता है: विस्तार के लिए खुला, संशोधन के लिए बंद।
24
EN + हिं
GB What is the output: class A{public: int x; virtual void f(){}}; class B:public A{}; sizeof(A), sizeof(B) on 64-bit?
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; आभासी शून्य f(){}}; कक्षा बी:सार्वजनिक ए{}; 64-बिट पर sizeof(A), sizeof(B)?
A
8 and 8 8 और 8
B
16 and 16 16 और 16
C
4 and 4 4 और 4
D
8 and 16 8 और 16
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A has int x (4 bytes) + vptr (8 bytes on 64-bit) = 16 (with alignment). B inherits same layout. Both 16.
व्याख्या (हिन्दी) A में int x (4 बाइट्स) + vptr (64-बिट पर 8 बाइट्स) = 16 (संरेखण के साथ) है। बी को वही लेआउट विरासत में मिला है। दोनों 16.
25
EN + हिं
GB What is 'dynamic dispatch overhead' in C++?
IN C++ में 'डायनामिक डिस्पैच ओवरहेड' क्या है?
A
Indirect function call through vtable pointer वीटेबल पॉइंटर के माध्यम से अप्रत्यक्ष फ़ंक्शन कॉल
B
Virtual function compilation वर्चुअल फ़ंक्शन संकलन
C
Runtime type checking cost रनटाइम प्रकार की जाँच लागत
D
Exception handling overhead ओवरहेड अपवाद हैंडलिंग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Virtual function call requires dereferencing vptr, looking up vtable, then calling — indirect call with potential cache miss overhead.
व्याख्या (हिन्दी) वर्चुअल फ़ंक्शन कॉल के लिए वीपीटीआर को डीरेफ़रेंसिंग, वीटेबल को देखना, फिर कॉलिंग की आवश्यकता होती है - संभावित कैश मिस ओवरहेड के साथ अप्रत्यक्ष कॉल।
26
EN + हिं
GB What is the output: class A{public: virtual void f()=0; virtual ~A()=default;}; class B:public A{public: void f(){cout<<'B';}}; A *p=new B; p->f(); delete p;
IN आउटपुट क्या है: क्लास ए{पब्लिक: वर्चुअल शून्य f()=0; आभासी ~ए()=डिफ़ॉल्ट;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() {काउट
A
B बी
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B implements f(). p->f() calls B::f(). Output: B.
व्याख्या (हिन्दी) बी एफ() लागू करता है। p->f() B::f() को कॉल करता है। आउटपुट: बी.
27
EN + हिं
GB What is 'override' specifier?
IN 'ओवरराइड' विनिर्देशक क्या है?
A
Checks at compile time that function actually overrides a virtual संकलन समय पर जाँचता है कि फ़ंक्शन वास्तव में वर्चुअल को ओवरराइड करता है
B
Makes function virtual फ़ंक्शन को वर्चुअल बनाता है
C
Prevents further overriding आगे ओवरराइडिंग को रोकता है
D
Marks function for optimization अनुकूलन के लिए मार्क्स कार्य करते हैं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) override tells the compiler to verify the function is actually overriding a base virtual; prevents silent bugs from signature mismatches.
व्याख्या (हिन्दी) ओवरराइड कंपाइलर को यह सत्यापित करने के लिए कहता है कि फ़ंक्शन वास्तव में बेस वर्चुअल को ओवरराइड कर रहा है; हस्ताक्षर बेमेल होने से साइलेंट बग को रोकता है।
28
EN + हिं
GB What is 'polymorphic type' in C++?
IN C++ में 'बहुरूपी प्रकार' क्या है?
A
Class with at least one virtual function कम से कम एक वर्चुअल फ़ंक्शन वाली कक्षा
B
Abstract class सार वर्ग
C
Class with multiple inheritance एकाधिक वंशानुक्रम वाला वर्ग
D
Template class टेम्पलेट वर्ग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A polymorphic type has at least one virtual function; RTTI and dynamic_cast work only with polymorphic types.
व्याख्या (हिन्दी) एक बहुरूपी प्रकार में कम से कम एक आभासी कार्य होता है; आरटीटीआई और डायनेमिक_कास्ट केवल बहुरूपी प्रकारों के साथ काम करते हैं।
29
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<1;}}; class B:public A{public: void f()override{cout<<2;}}; B b; A&r=b; r.A::f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
1 1
B
2 2
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) r.A::f() explicitly calls A's f(), bypassing virtual dispatch. Output: 1.
व्याख्या (हिन्दी) r.A::f() वर्चुअल डिस्पैच को दरकिनार करते हुए स्पष्ट रूप से A के f() को कॉल करता है। आउटपुट: 1.
30
EN + हिं
GB What is the output: class A{public:virtual int f(){return 1;}}; class B:public A{public:int f()override{return 2;}}; A *p=new B; cout<f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ(){रिटर्न 1;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f()ओवरराइड{वापसी 2;}}; ए *पी=नया बी; अदालत
A
2 2
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f(). Output: 2.
व्याख्या (हिन्दी) बी::एफ(). आउटपुट: 2.
16–30 of 94