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
241
EN + हिं
GB What is a 'nested class' in C++?
IN C++ में 'नेस्टेड क्लास' क्या है?
A
A class defined inside another class एक वर्ग को दूसरे वर्ग के अंदर परिभाषित किया गया है
B
A class with multiple inheritance एकाधिक वंशानुक्रम वाला एक वर्ग
C
A template class एक टेम्पलेट क्लास
D
Abstract class सार वर्ग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A nested class is defined within the scope of an enclosing class.
व्याख्या (हिन्दी) एक नेस्टेड वर्ग को एक संलग्न वर्ग के दायरे में परिभाषित किया गया है।
242
EN + हिं
GB What is the output: class A{public: ~A(){cout<<'D';}}; A *p=new A; delete p;
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: ~ ए() {काउट
A
D डी
B
Nothing कुछ नहीं
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) delete p calls destructor, which prints D.
व्याख्या (हिन्दी) डिलीट पी कॉल डिस्ट्रक्टर, जो डी प्रिंट करता है।
243
EN + हिं
GB What is 'method chaining' in C++?
IN C++ में 'मेथड चेनिंग' क्या है?
A
Returning *this from member functions to chain calls *इसे सदस्य फ़ंक्शंस से चेन कॉल पर लौटाना
B
Calling multiple methods sequentially एकाधिक विधियों को क्रमिक रूप से कॉल करना
C
Virtual method dispatch आभासी विधि प्रेषण
D
Template method pattern टेम्पलेट विधि पैटर्न
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Returning *this from methods enables: obj.setX(1).setY(2).setZ(3) style chaining.
व्याख्या (हिन्दी) तरीकों से इसे वापस करने से सक्षम होता है: obj.setX(1).setY(2).setZ(3) स्टाइल चेनिंग।
244
EN + हिं
GB What is the output: struct A{int x,y; A(int a,int b):x(a),y(b){}}; A a{3,4}; cout<
IN आउटपुट क्या है: struct A{int x,y; A(int a,int b):x(a),y(b){}}; ए ए{3,4}; अदालत
A
7 7
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A a{3,4} calls constructor: x=3,y=4. x+y=7. Output: 7.
व्याख्या (हिन्दी) A a{3,4} कंस्ट्रक्टर को कॉल करता है: x=3,y=4। x+y=7. आउटपुट: 7.
245
EN + हिं
GB What is 'CRTP' (Curiously Recurring Template Pattern)?
IN 'सीआरटीपी' (क्यूरियसली रिकरिंग टेम्पलेट पैटर्न) क्या है?
A
Base class template parameterized with derived class बेस क्लास टेम्पलेट को व्युत्पन्न क्लास के साथ पैरामीटरयुक्त किया गया है
B
Recursive template instantiation पुनरावर्ती टेम्पलेट इन्स्टेन्शियशन
C
Multiple inheritance pattern एकाधिक वंशानुक्रम पैटर्न
D
Virtual function replacement वर्चुअल फ़ंक्शन प्रतिस्थापन
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) CRTP: template class Base{}; class Derived: public Base{}; enables static polymorphism.
व्याख्या (हिन्दी) सीआरटीपी: टेम्पलेट क्लास बेस{}; वर्ग व्युत्पन्न: सार्वजनिक आधार{}; स्थैतिक बहुरूपता को सक्षम बनाता है।
246
EN + हिं
GB What is the output: class A{public: int x=5; int& f(){return x;}}; A a; a.f()=10; cout<
IN आउटपुट क्या है: class A{public: int x=5; int& f(){रिटर्न x;}}; ए ए; a.f()=10; अदालत
A
5 5
B
10 10
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f() returns reference to x. Assigning 10 to it sets x=10. Output: 10.
व्याख्या (हिन्दी) f() x का संदर्भ लौटाता है। इसमें 10 निर्दिष्ट करने पर x=10 सेट हो जाता है। आउटपुट: 10.
247
EN + हिं
GB What is the output: class A{int x=0; public: void inc(){x++;} int get()const{return x;}}; A a,b=a; a.inc(); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: void inc(){x++;} int get()const{return x;}}; ए ए,बी=ए; a.inc(); अदालत
A
10 10
B
11 11
C
01 01
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b is a copy of a (x=0). a.inc() makes a.x=1. b.x stays 0. Output: 10.
व्याख्या (हिन्दी) b, a (x=0) की एक प्रति है। a.inc() a.x=1 बनाता है। b.x 0 रहता है। आउटपुट: 10।
248
EN + हिं
GB What is 'type punning' in C++?
IN C++ में 'टाइप पनिंग' क्या है?
A
Reinterpreting memory as different type स्मृति को भिन्न प्रकार के रूप में पुनःव्याख्या करना
B
Type aliasing with typedef टाइपडिफ के साथ अलियासिंग टाइप करें
C
Template specialization टेम्पलेट विशेषज्ञता
D
Dynamic casting गतिशील कास्टिंग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Type punning reads object representation as a different type, often via union or memcpy, sometimes undefined behavior with pointer casts.
व्याख्या (हिन्दी) टाइप पनिंग ऑब्जेक्ट प्रतिनिधित्व को एक अलग प्रकार के रूप में पढ़ता है, अक्सर यूनियन या मेम्सीपी के माध्यम से, कभी-कभी पॉइंटर कास्ट के साथ अपरिभाषित व्यवहार।
249
EN + हिं
GB What is the output: class A{public: virtual void f(){cout<<'A';}}; class B:public A{public: void f()override{cout<<'B';}}; A*p=new B; p->f(); delete p;
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
A
B
B बी
C
AB अब
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Virtual dispatch: p is A* pointing to B object. p->f() calls B::f() via vtable. Output: B.
व्याख्या (हिन्दी) आभासी प्रेषण: p, A* है जो B ऑब्जेक्ट की ओर इशारा करता है। p->f() vtable के माध्यम से B::f() को कॉल करता है। आउटपुट: बी.
250
EN + हिं
GB What is the output: class A{public: A(){cout<<'A';} A(const A&){cout<<'C';}}; A f(){return A();} A a=f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
A
B
AC ए.सी
C
ACC एसीसी
D
AA
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) RVO/copy elision (mandatory in C++17 for prvalues) eliminates copies; only one constructor call. Output: A.
व्याख्या (हिन्दी) आरवीओ/कॉपी एलिज़न (प्रचलन के लिए C++17 में अनिवार्य) प्रतियों को समाप्त करता है; केवल एक कंस्ट्रक्टर कॉल। आउटपुट: ए.
251
EN + हिं
GB What is the order of constructor calls in: class A{}; class B:public A{};?
IN कंस्ट्रक्टर कॉल का क्रम क्या है: क्लास ए {}; कक्षा बी:सार्वजनिक ए{};?
A
B then A बी फिर ए
B
A then B ए फिर बी
C
Simultaneous समकालिक
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Base class constructor (A) is called before derived class constructor (B).
व्याख्या (हिन्दी) बेस क्लास कंस्ट्रक्टर (ए) को व्युत्पन्न क्लास कंस्ट्रक्टर (बी) से पहले कहा जाता है।
252
EN + हिं
GB What is the output: class A{public: A(){cout<<1;} ~A(){cout<<2;}}; A a;
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
12 12
B
21 21
C
1 1
D
2 2
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Constructor prints 1 at creation, destructor prints 2 at end of scope. Output: 12.
व्याख्या (हिन्दी) निर्माण के समय कंस्ट्रक्टर 1 प्रिंट करता है, स्कोप के अंत में डिस्ट्रक्टर 2 प्रिंट करता है। आउटपुट: 12.
253
EN + हिं
GB What is a 'delegating constructor' in C++11?
IN C++11 में 'डेलीगेटिंग कंस्ट्रक्टर' क्या है?
A
Constructor calling another constructor of same class कंस्ट्रक्टर उसी क्लास के दूसरे कंस्ट्रक्टर को बुला रहा है
B
Constructor in derived class व्युत्पन्न वर्ग में कंस्ट्रक्टर
C
Constructor with default args डिफ़ॉल्ट आर्ग के साथ कंस्ट्रक्टर
D
Virtual constructor वर्चुअल कंस्ट्रक्टर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A delegating constructor: A():A(0){} — calls A(int) constructor to initialize.
व्याख्या (हिन्दी) एक प्रतिनिधि कंस्ट्रक्टर: A():A(0){} - प्रारंभ करने के लिए A(int) कंस्ट्रक्टर को कॉल करता है।
254
EN + हिं
GB What is the output: struct A{int x,y; A(int a=0,int b=0):x(a),y(b){}}; A a(1,2); cout<
IN What is the output: struct A{int x,y; A(int a=0,int b=0):x(a),y(b){}}; ए ए(1,2); अदालत
A
12 12
B
21 21
C
00 00
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=1, y=2. Output: 12.
व्याख्या (हिन्दी) x=1, y=2. आउटपुट: 12.
255
EN + हिं
GB What is the output: class A{public: A(){cout<<'A';} A(const A&){cout<<'C';} ~A(){cout<<'D';}}; A a; A b(a);
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
ACD एसीडी
B
ACDD एसीडीडी
C
AADD AADD
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a: ctor prints A. b(a): copy ctor prints C. End of scope: ~b prints D, ~a prints D (reverse order). Output: ACDD.
व्याख्या (हिन्दी) a: ctor प्रिंट A. b(a): कॉपी ctor प्रिंट C. स्कोप का अंत: ~b प्रिंट D, ~a प्रिंट D (रिवर्स ऑर्डर)। आउटपुट: एसीडीडी।
241–255 of 1915