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
286
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 &r=*new B; r.f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
A
B
B बी
C
AB अब
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) r is reference to A but bound to B. Virtual dispatch calls B::f(). Output: B.
व्याख्या (हिन्दी) r, A का संदर्भ है लेकिन B से जुड़ा है। वर्चुअल प्रेषण कॉल B::f() है। आउटपुट: बी.
287
EN + हिं
GB What is 'protected' access specifier?
IN 'संरक्षित' पहुंच विनिर्देशक क्या है?
A
Accessible in class and derived classes only केवल कक्षा और व्युत्पन्न कक्षाओं में पहुंच योग्य
B
Accessible everywhere हर जगह पहुंच योग्य
C
Accessible only in class केवल कक्षा में ही पहुंच योग्य
D
Accessible in same file एक ही फ़ाइल में पहुंचयोग्य
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) protected members are accessible within the class and its derived classes, but not from outside.
व्याख्या (हिन्दी) संरक्षित सदस्य वर्ग और उसके व्युत्पन्न वर्गों के भीतर पहुंच योग्य हैं, लेकिन बाहर से नहीं।
288
EN + हिं
GB What is the output: class A{public: int x=1;}; class B:public A{public: int x=2;}; B b; cout<
IN आउटपुट क्या है: class A{public: int x=1;}; कक्षा बी:सार्वजनिक ए{सार्वजनिक: int x=2;}; बी बी; अदालत
A
21 21
B
12 12
C
11 11
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b.x refers to B::x=2. b.A::x explicitly accesses A::x=1. Output: 21.
व्याख्या (हिन्दी) b.x, B::x=2 को संदर्भित करता है। b.A::x स्पष्ट रूप से A::x=1 तक पहुँचता है। आउटपुट: 21.
289
EN + हिं
GB What is 'private inheritance'?
IN 'निजी विरासत' क्या है?
A
Base class public/protected members become private in derived बेस क्लास सार्वजनिक/संरक्षित सदस्य व्युत्पन्न में निजी बन जाते हैं
B
Inheriting private members निजी सदस्यों को विरासत में मिलाना
C
Preventing inheritance वंशानुक्रम को रोकना
D
Inheriting private functions only केवल निजी कार्य विरासत में मिले
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Private inheritance means all inherited public/protected members of base become private in the derived class.
व्याख्या (हिन्दी) निजी विरासत का मतलब है कि आधार के सभी विरासत में मिले सार्वजनिक/संरक्षित सदस्य व्युत्पन्न वर्ग में निजी बन जाते हैं।
290
EN + हिं
GB What is the output: struct B{int x=10;}; struct D:B{int y=20;}; D d; cout<
IN आउटपुट क्या है: struct B{int x=10;}; संरचना D:B{int y=20;}; डी डी; अदालत
A
4 4
B
8 8
C
20 20
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) sizeof(D) = sizeof(B)+sizeof(D's own) = 4+4=8 (assuming int=4).
व्याख्या (हिन्दी) आकार(डी) = आकार(बी)+आकार(डी का अपना) = 4+4=8 (पूर्णांक=4 मानते हुए)।
291
EN + हिं
GB What is the output: class A{public: virtual void f()=0;}; class B:public A{public: void f(){cout<<'B';}}; A *p=new B; p->f();
IN आउटपुट क्या है: क्लास ए{सार्वजनिक: वर्चुअल शून्य f()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() {काउट
A
A
B
B बी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B implements pure virtual f(). p->f() calls B::f() via vtable. Output: B.
व्याख्या (हिन्दी) बी शुद्ध वर्चुअल एफ() लागू करता है। p->f() vtable के माध्यम से B::f() को कॉल करता है। आउटपुट: बी.
292
EN + हिं
GB What is 'slicing' problem?
IN 'स्लाइसिंग' समस्या क्या है?
A
Derived-specific data lost when copying to base object बेस ऑब्जेक्ट पर कॉपी करते समय व्युत्पन्न-विशिष्ट डेटा खो जाता है
B
Memory fragmentation स्मृति विखंडन
C
Virtual function removal वर्चुअल फ़ंक्शन हटाना
D
Stack overflow स्टैक ओवरफ़्लो
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Object slicing occurs when a derived object is assigned to a base object by value, losing the derived portion.
व्याख्या (हिन्दी) ऑब्जेक्ट स्लाइसिंग तब होती है जब एक व्युत्पन्न ऑब्जेक्ट को मूल्य के आधार पर बेस ऑब्जेक्ट को सौंपा जाता है, जिससे व्युत्पन्न भाग खो जाता है।
293
EN + हिं
GB What is the output: class A{public: void f(){cout<<'A';} virtual void g(){cout<<'a';}}; class B:public A{public: void f(){cout<<'B';} void g()override{cout<<'b';}}; A*p=new B; p->f(); p->g();
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: शून्य एफ() {काउट
A
ABab अबाब
B
Ab अब
C
AB अब
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f(): non-virtual, calls A::f() (static binding) = 'A'. p->g(): virtual, calls B::g() = 'b'. Output: Ab.
व्याख्या (हिन्दी) p->f(): गैर-आभासी, कॉल A::f() (स्थैतिक बाइंडिंग) = 'A'। p->g(): वर्चुअल, कॉल B::g() = 'b'। आउटपुट: एब.
294
EN + हिं
GB What is 'final' keyword in C++11?
IN C++11 में 'अंतिम' कीवर्ड क्या है?
A
Prevents further inheritance or overriding आगे की विरासत या ओवरराइडिंग को रोकता है
B
Makes class immutable कक्षा को अपरिवर्तनीय बनाता है
C
Equivalent to sealed सीलबंद के बराबर
D
Makes destructor virtual विध्वंसक को आभासी बनाता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) class A final{} prevents any class from inheriting A. virtual void f() final prevents overriding f.
व्याख्या (हिन्दी) क्लास ए फाइनल {} किसी भी क्लास को ए इनहेरिट करने से रोकता है। वर्चुअल शून्य एफ() फाइनल एफ को ओवरराइड करने से रोकता है।
295
EN + हिं
GB What is the output: class A{public: int x; A(int v):x(v){}}; class B:public A{public: B():A(5){}}; B b; cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; A(int v):x(v){}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक: बी():ए(5){}}; बी बी; अदालत
A
5 5
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B's constructor delegates to A(5), setting x=5. Output: 5.
व्याख्या (हिन्दी) B का कंस्ट्रक्टर x=5 सेट करते हुए A(5) को सौंपता है। आउटपुट: 5.
296
EN + हिं
GB What is 'covariant return type'?
IN 'सहसंयोजक रिटर्न प्रकार' क्या है?
A
Overriding function may return derived type of base's return type ओवरराइडिंग फ़ंक्शन आधार के रिटर्न प्रकार का व्युत्पन्न प्रकार लौटा सकता है
B
Returning const reference रिटर्निंग कॉन्स्ट संदर्भ
C
Template return type deduction टेम्प्लेट रिटर्न प्रकार कटौती
D
Auto return type ऑटो रिटर्न प्रकार
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A virtual function override may return a pointer/reference to a derived type of the base function's return type.
व्याख्या (हिन्दी) एक वर्चुअल फ़ंक्शन ओवरराइड बेस फ़ंक्शन के रिटर्न प्रकार के व्युत्पन्न प्रकार के लिए एक पॉइंटर/संदर्भ लौटा सकता है।
297
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 प्रिंट करता है)। आउटपुट: एबी.
298
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{};
299
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.
व्याख्या (हिन्दी) पी हटाएं: वर्चुअल डिस्ट्रक्टर पहले बी::~बी को कॉल करता है (बी प्रिंट करता है), फिर ए::~ए (ए प्रिंट करता है)। आउटपुट: बी.ए.
300
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) होता है और इसे सीधे इंस्टेंट नहीं किया जा सकता है।
286–300 of 1915