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
331
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.
व्याख्या (हिन्दी) ए में वर्चुअल डिस्ट्रक्टर के बिना, सी से ए* को हटाना अपरिभाषित व्यवहार है; केवल ए के विध्वंसक को ही बुलाया जा सकता है।
332
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 ऑब्जेक्ट लौटाता है; बहुरूपी प्रकारों के लिए कम से कम एक वर्चुअल फ़ंक्शन की आवश्यकता होती है।
333
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.
334
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.
व्याख्या (हिन्दी) बहुरूपता (विशेषकर आभासी कार्य) खुले/बंद सिद्धांत का समर्थन करता है: विस्तार के लिए खुला, संशोधन के लिए बंद।
335
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.
336
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.
व्याख्या (हिन्दी) वर्चुअल फ़ंक्शन कॉल के लिए वीपीटीआर को डीरेफ़रेंसिंग, वीटेबल को देखना, फिर कॉलिंग की आवश्यकता होती है - संभावित कैश मिस ओवरहेड के साथ अप्रत्यक्ष कॉल।
337
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() को कॉल करता है। आउटपुट: बी.
338
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.
व्याख्या (हिन्दी) ओवरराइड कंपाइलर को यह सत्यापित करने के लिए कहता है कि फ़ंक्शन वास्तव में बेस वर्चुअल को ओवरराइड कर रहा है; हस्ताक्षर बेमेल होने से साइलेंट बग को रोकता है।
339
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.
व्याख्या (हिन्दी) एक बहुरूपी प्रकार में कम से कम एक आभासी कार्य होता है; आरटीटीआई और डायनेमिक_कास्ट केवल बहुरूपी प्रकारों के साथ काम करते हैं।
340
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.
341
EN + हिं
GB What is encapsulation?
IN एनकैप्सुलेशन क्या है?
A
Bundling data and methods, controlling access डेटा और विधियों को बंडल करना, पहुंच को नियंत्रित करना
B
Hiding implementation in header हेडर में कार्यान्वयन छुपाया जा रहा है
C
Making all members private सभी सदस्यों को निजी बनाना
D
Using namespaces नामस्थानों का उपयोग करना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Encapsulation combines data and methods in a class and controls access via access specifiers.
व्याख्या (हिन्दी) एनकैप्सुलेशन एक क्लास में डेटा और विधियों को जोड़ता है और एक्सेस स्पेसिफायर के माध्यम से एक्सेस को नियंत्रित करता है।
342
EN + हिं
GB What is the output: class A{int x=42; public: int get()const{return x;}}; A a; cout<
IN आउटपुट क्या है: class A{int x=42; सार्वजनिक: int get()const{return x;}}; ए ए; अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x is private but get() is public and returns x=42. Output: 42.
व्याख्या (हिन्दी) x निजी है लेकिन get() सार्वजनिक है और x=42 लौटाता है। आउटपुट: 42.
343
EN + हिं
GB What does 'const' member function guarantee?
IN 'कॉन्स्ट' सदस्य फ़ंक्शन क्या गारंटी देता है?
A
Doesn't modify non-mutable data members गैर-परिवर्तनीय डेटा सदस्यों को संशोधित नहीं करता है
B
Immutable object अपरिवर्तनीय वस्तु
C
Thread-safe function थ्रेड-सुरक्षित फ़ंक्शन
D
Inline function इनलाइन फ़ंक्शन
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A const member function cannot modify data members (except mutable ones) and can be called on const objects.
व्याख्या (हिन्दी) एक कॉन्स्ट मेंबर फ़ंक्शन डेटा सदस्यों (म्यूटेबल को छोड़कर) को संशोधित नहीं कर सकता है और इसे कॉन्स्ट ऑब्जेक्ट पर कॉल किया जा सकता है।
344
EN + हिं
GB What is the output: class A{public: int x; void setX(int v){x=v;} int getX(){return x;}}; A a; a.setX(10); cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; void setX(int v){x=v;} int getX(){return x;}}; ए ए; ए.सेटएक्स(10); अदालत
A
10 10
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) setX(10) sets x=10, getX() returns x=10. Output: 10.
व्याख्या (हिन्दी) setX(10) x=10 सेट करता है, getX() x=10 लौटाता है। आउटपुट: 10.
345
EN + हिं
GB What is 'information hiding'?
IN 'जानकारी छिपाना' क्या है?
A
Hiding implementation details from users उपयोगकर्ताओं से कार्यान्वयन विवरण छिपाना
B
Runtime data hiding रनटाइम डेटा छिपाना
C
Encryption कूटलेखन
D
Namespace hiding नेमस्पेस छिपाना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Information hiding prevents direct access to implementation details, exposing only necessary interface.
व्याख्या (हिन्दी) सूचना छिपाना कार्यान्वयन विवरण तक सीधी पहुंच को रोकता है, केवल आवश्यक इंटरफ़ेस को उजागर करता है।
331–345 of 1915