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
1
EN + हिं
GB What is the output: class A{public: void f(){cout<<'A';}}; class B:public A{public: void f(){cout<<'B';}}; B b; b.f();
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: शून्य एफ() {काउट
A
A
B
B बी
C
AB अब
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f() hides A::f(). b.f() calls B's version. Output: B.
व्याख्या (हिन्दी) B::f() A::f() को छुपाता है। b.f() B के संस्करण को कॉल करता है। आउटपुट: बी.
2
EN + हिं
GB What is 'diamond problem' in C++?
IN C++ में 'डायमंड प्रॉब्लम' क्या है?
A
Ambiguity when class inherits from two classes sharing a base अस्पष्टता जब वर्ग को आधार साझा करने वाले दो वर्गों से विरासत मिलती है
B
Memory diamond shape स्मृति हीरे का आकार
C
Multiple constructors एकाधिक निर्माणकर्ता
D
Template diamond टेम्पलेट हीरा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Diamond problem: D inherits B and C, both inherit A. D has two copies of A unless virtual inheritance is used.
व्याख्या (हिन्दी) हीरे की समस्या: D को B और C विरासत में मिले हैं, दोनों को A विरासत में मिला है। D के पास A की दो प्रतियां हैं जब तक कि आभासी विरासत का उपयोग नहीं किया जाता है।
3
EN + हिं
GB What is the output: class A{public: A(){cout<<'A';}}; class B:public A{public: B(){cout<<'B';}}; class C:public B{public: C(){cout<<'C';}}; C c;
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
CBA सीबीए
B
ABC एबीसी
C
BAC बीएसी
D
CAB कैब
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Base classes constructed first (top-down): A then B then C. Output: ABC.
व्याख्या (हिन्दी) बेस क्लास का निर्माण पहले (ऊपर से नीचे): ए, फिर बी, फिर सी। आउटपुट: एबीसी।
4
EN + हिं
GB What is virtual inheritance?
IN आभासी विरासत क्या है?
A
Ensures single base class instance in diamond inheritance हीरे की विरासत में एकल आधार वर्ग उदाहरण सुनिश्चित करता है
B
Virtual function inheritance वर्चुअल फ़ंक्शन इनहेरिटेंस
C
Pure virtual class शुद्ध आभासी कक्षा
D
Multiple inheritance एकाधिक वंशानुक्रम
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) virtual inheritance prevents multiple copies of base class in diamond hierarchy by sharing a single base instance.
व्याख्या (हिन्दी) वर्चुअल इनहेरिटेंस एकल बेस इंस्टेंस को साझा करके डायमंड पदानुक्रम में बेस क्लास की कई प्रतियों को रोकता है।
5
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() है। आउटपुट: बी.
6
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.
व्याख्या (हिन्दी) संरक्षित सदस्य वर्ग और उसके व्युत्पन्न वर्गों के भीतर पहुंच योग्य हैं, लेकिन बाहर से नहीं।
7
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.
8
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.
व्याख्या (हिन्दी) निजी विरासत का मतलब है कि आधार के सभी विरासत में मिले सार्वजनिक/संरक्षित सदस्य व्युत्पन्न वर्ग में निजी बन जाते हैं।
9
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 मानते हुए)।
10
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() को कॉल करता है। आउटपुट: बी.
11
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.
व्याख्या (हिन्दी) ऑब्जेक्ट स्लाइसिंग तब होती है जब एक व्युत्पन्न ऑब्जेक्ट को मूल्य के आधार पर बेस ऑब्जेक्ट को सौंपा जाता है, जिससे व्युत्पन्न भाग खो जाता है।
12
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'। आउटपुट: एब.
13
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.
व्याख्या (हिन्दी) क्लास ए फाइनल {} किसी भी क्लास को ए इनहेरिट करने से रोकता है। वर्चुअल शून्य एफ() फाइनल एफ को ओवरराइड करने से रोकता है।
14
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.
15
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.
व्याख्या (हिन्दी) एक वर्चुअल फ़ंक्शन ओवरराइड बेस फ़ंक्शन के रिटर्न प्रकार के व्युत्पन्न प्रकार के लिए एक पॉइंटर/संदर्भ लौटा सकता है।
1–15 of 104