OOP Using C++ — MCQ Practice

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

📚 104 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
104 questions
16
EN + हिं
GB What is the output: class A{public: A(int){cout<<'A';}}; class B:public A{public: B():A(0){cout<<'B';}}; B b;
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए (इंट) {काउट
A
AB अब
B
BA बी ० ए
C
B बी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A(0) constructed first (prints A), then B (prints B). Output: AB.
व्याख्या (हिन्दी) A(0) ने पहले निर्माण किया (A प्रिंट करता है), फिर B (B प्रिंट करता है)। आउटपुट: एबी.
17
EN + हिं
GB What is 'multiple inheritance' in C++?
IN C++ में 'एकाधिक वंशानुक्रम' क्या है?
A
Class inheriting from more than one base class एक से अधिक बेस क्लास से विरासत में मिला वर्ग
B
Multiple objects of same class एक ही कक्षा की अनेक वस्तुएँ
C
Multiple constructor overloads एकाधिक कंस्ट्रक्टर ओवरलोड
D
Multiple virtual functions एकाधिक आभासी कार्य
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C++ allows a class to inherit from multiple base classes: class C: public A, public B{};
व्याख्या (हिन्दी) C++ एक क्लास को कई बेस क्लास से इनहेरिट करने की अनुमति देता है: क्लास C: पब्लिक A, पब्लिक B{};
18
EN + हिं
GB What is the output: class A{public: virtual ~A(){cout<<'A';}}; class B:public A{public: ~B()override{cout<<'B';}}; A*p=new B; delete p;
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल ~ ए() {काउट
A
AB अब
B
BA बी ० ए
C
B बी
D
A
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) delete p: virtual destructor calls B::~B first (prints B), then A::~A (prints A). Output: BA.
व्याख्या (हिन्दी) पी हटाएं: वर्चुअल डिस्ट्रक्टर पहले बी::~बी को कॉल करता है (बी प्रिंट करता है), फिर ए::~ए (ए प्रिंट करता है)। आउटपुट: बी.ए.
19
EN + हिं
GB What is 'abstract class' in C++?
IN C++ में 'अमूर्त वर्ग' क्या है?
A
Class with at least one pure virtual function कम से कम एक शुद्ध आभासी फ़ंक्शन वाला वर्ग
B
Class with no members बिना किसी सदस्य वाली कक्षा
C
Class with only virtual functions केवल आभासी कार्यों वाली कक्षा
D
Template class टेम्पलेट वर्ग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) An abstract class has at least one pure virtual function (=0) and cannot be directly instantiated.
व्याख्या (हिन्दी) एक अमूर्त वर्ग में कम से कम एक शुद्ध वर्चुअल फ़ंक्शन (=0) होता है और इसे सीधे इंस्टेंट नहीं किया जा सकता है।
20
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.
21
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 कॉल करता है। आउटपुट: ए.
22
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++ में इंटरफ़ेस केवल शुद्ध वर्चुअल फ़ंक्शंस और बिना किसी डेटा सदस्य के अमूर्त वर्गों का उपयोग करके सिम्युलेटेड होते हैं।
23
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।
24
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 के माध्यम से कॉल किया जाता है। आउटपुट: जी.
25
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.
व्याख्या (हिन्दी) एक संरक्षित कंस्ट्रक्टर प्रत्यक्ष इंस्टेंशियेशन को रोकता है लेकिन व्युत्पन्न क्लास कंस्ट्रक्टर्स को इसे कॉल करने की अनुमति देता है।
26
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.
27
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.
व्याख्या (हिन्दी) ईबीओ कंपाइलर को मेमोरी को अनुकूलित करते हुए, आधार के रूप में उपयोग किए जाने पर खाली बेस क्लास को शून्य आकार देने की अनुमति देता है।
28
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.
29
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.
व्याख्या (हिन्दी) निर्माण: ए (प्रिंट ए), बी (प्रिंट बी)। नष्ट करें: ~बी (बी प्रिंट करता है), ~ए (ए प्रिंट करता है)। आउटपुट: एबीबीए.
30
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 का उपयोग करने से सदस्य व्युत्पन्न वर्ग नाम के तहत पहुंच योग्य हो जाता है और ओवरलोड रिज़ॉल्यूशन को प्रभावित करता है।
16–30 of 104