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
871
EN + हिं
GB What is 'covariant return type' example?
IN 'सहसंयोजक रिटर्न प्रकार' उदाहरण क्या है?
A
Base:virtual A* f(); Derived:B* f() where B derives A आधार:वर्चुअल ए* एफ(); व्युत्पन्न:B* f() जहां B से A प्राप्त होता है
B
Same return type always हमेशा एक ही रिटर्न प्रकार
C
Template return टेम्पलेट वापसी
D
void return only केवल शून्य वापसी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Overriding may return derived pointer/reference of base's return type.
व्याख्या (हिन्दी) ओवरराइडिंग से आधार के रिटर्न प्रकार का व्युत्पन्न सूचक/संदर्भ वापस आ सकता है।
872
EN + हिं
GB What is the output: struct A{int x=1;}; struct B:A{int y=2;}; struct C:B{int z=3;}; C c; cout<
IN आउटपुट क्या है: struct A{int x=1;}; संरचना बी:ए{int y=2;}; संरचना C:B{int z=3;}; सी सी; अदालत
A
123 123
B
321 321
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) All inherited. x=1,y=2,z=3. Output: 123.
व्याख्या (हिन्दी) सब विरासत में मिला. x=1,y=2,z=3. आउटपुट: 123.
873
EN + हिं
GB What is the output: class A{public:virtual void f()=0; void g(){f();}}; class B:public A{public:void f(){cout<<'B';}}; B b; b.g();
IN आउटपुट क्या है: class A{public:virtual void f()=0; शून्य g(){f();}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() {काउट
A
B बी
B
A
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() calls virtual f(); dispatches to B::f(). Output: B.
व्याख्या (हिन्दी) g() वर्चुअल f() को कॉल करता है; B::f() को भेजता है। आउटपुट: बी.
874
EN + हिं
GB What is the output: class A{public:int x=0; virtual void f(){x=1;}}; class B:public A{public:void f()override{x=2;}}; A *p=new B; p->f(); cout<x;
IN आउटपुट क्या है: class A{public:int x=0; आभासी शून्य f(){x=1;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:शून्य f()ओवरराइड{x=2;}}; ए *पी=नया बी; p->f(); अदालत
A
2 2
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f() dispatches to B::f(); x=2. Output: 2.
व्याख्या (हिन्दी) p->f() B::f() को भेजता है; एक्स=2. आउटपुट: 2.
875
EN + हिं
GB What is the output: class A{public:int x=5; virtual int f(){return x;}}; class B:public A{public:int f()override{return x*2;}}; A a; B b; A&r=b; cout<
IN आउटपुट क्या है: class A{public:int x=5; वर्चुअल int f(){रिटर्न x;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f()ओवरराइड{वापसी x*2;}}; ए ए; बी बी; ए&आर=बी; अदालत
A
510 510
B
55 55
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.f()=5; r.f() virtual dispatch: B::f()=5*2=10. Output: 510.
व्याख्या (हिन्दी) a.f()=5; r.f() वर्चुअल प्रेषण: B::f()=5*2=10। आउटपुट: 510.
876
EN + हिं
GB What is the output: class A{public:void f(){cout<<'A';}}; class B:public A{using A::f;}; B b; b.f();
IN आउटपुट क्या है: कक्षा ए {सार्वजनिक: शून्य एफ() {काउट
A
A
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
B बी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) using A::f makes A::f accessible as B::f. b.f()=A. Output: A.
व्याख्या (हिन्दी) A::f का उपयोग करने से A::f को B::f के रूप में पहुंच योग्य बनाया जा सकता है। बी.एफ()=ए. आउटपुट: ए.
877
EN + हिं
GB What is the output: class Base{public:int x=1; virtual int f(){return x;}}; class Mid:public Base{public:int x=2; int f()override{return x;}}; class Der:public Mid{public:int x=3;}; Der d; Base*p=&d; cout<f();
IN आउटपुट क्या है: class Base{public:int x=1; वर्चुअल int f(){रिटर्न x;}}; कक्षा मध्य:सार्वजनिक आधार{सार्वजनिक:int x=2; int f()ओवरराइड{रिटर्न x;}}; वर्ग डेर:सार्वजनिक मध्य{सार्वजनिक:int x=3;}; डेर डी; आधार*p=&d; अदालत
A
2 2
B
3 3
C
1 1
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Mid::f() uses Mid::x=2 (its own). Output: 2.
व्याख्या (हिन्दी) मिड::एफ() मिड::एक्स=2 (स्वयं का) का उपयोग करता है। आउटपुट: 2.
878
EN + हिं
GB What is the output: class A{public:virtual ~A(){cout<<'A';}}; class B:public A{public:~B(){cout<<'B';}}; A*p=new B; delete p;
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल ~ए(){काउट
A
BA बी ० ए
B
AB अब
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) delete p: ~B() first=B, then ~A()=A. Output: BA.
व्याख्या (हिन्दी) p हटाएं: ~B() पहले=B, फिर ~A()=A. आउटपुट: बी.ए.
879
EN + हिं
GB What is the output: class A{public:int f(int x){return x*2;}}; class B:public A{public:int f(double x){return x*3;}}; B b; cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int f (int x) {रिटर्न x * 2;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f(डबल x){रिटर्न x*3;}}; बी बी; अदालत
A
15 15
B
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f(double) hides A::f. b.f(5): 5 converts to double; B::f(5.0)=5*3=15. Output: 15.
व्याख्या (हिन्दी) B::f(double) A::f को छुपाता है। बी.एफ(5): 5 डबल में परिवर्तित होता है; बी::एफ(5.0)=5*3=15. आउटपुट: 15.
880
EN + हिं
GB What is the output: class A{public:int x=0; A(int v=0):x(v){}}; class B:public A{public:B(int v):A(v*2){}}; B b(3); cout<
IN आउटपुट क्या है: class A{public:int x=0; A(int v=0):x(v){}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:बी(int v):ए(v*2){}}; बी बी(3); अदालत
A
6 6
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A(3*2=6): x=6. Output: 6.
व्याख्या (हिन्दी) ए(3*2=6): एक्स=6। आउटपुट: 6.
881
EN + हिं
GB What is the output: class A{protected:void f(){cout<<'A';}}; class B:public A{public:void g(){f();}}; B b; b.g();
IN आउटपुट क्या है: क्लास ए {संरक्षित: शून्य एफ() {काउट
A
A
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() calls protected f(). Output: A.
व्याख्या (हिन्दी) g() संरक्षित f() को कॉल करता है। आउटपुट: ए.
882
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;} virtual void g(){cout<<2;}}; class B:public A{public:void f()override{cout<<3;}}; A*p=new B; p->f(); p->g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
32 32
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f(): B::f()=3; p->g(): A::g()=2. Output: 32.
व्याख्या (हिन्दी) p->f(): B::f()=3; p->g(): A::g()=2. आउटपुट: 32.
883
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){}}; class B:public A{public:using A::A;}; B b(42); cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: ए का उपयोग करना:: ए;}; बी बी(42); अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) using A::A inherits A(int). B b(42) calls A(42). x=42. Output: 42.
व्याख्या (हिन्दी) A::A का उपयोग करने से A(int) प्राप्त होता है। बी बी(42) ए(42) को कॉल करता है। एक्स=42. आउटपुट: 42.
884
EN + हिं
GB What is 'empty base class optimization' (EBO)?
IN 'खाली बेस क्लास अनुकूलन' (ईबीओ) क्या है?
A
Empty base takes no space in derived object खाली आधार व्युत्पन्न वस्तु में कोई स्थान नहीं लेता है
B
Only for virtual bases केवल आभासी आधारों के लिए
C
Compiler-specific संकलक-विशिष्ट
D
C++17 mandatory C++17 अनिवार्य
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) If base class is empty, derived object need not be larger; EBO allows zero overhead.
व्याख्या (हिन्दी) यदि बेस क्लास खाली है, तो व्युत्पन्न वस्तु को बड़ा होने की आवश्यकता नहीं है; ईबीओ शून्य ओवरहेड की अनुमति देता है।
885
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';}}; class B:public A{}; class C:public A{public:void f()override{cout<<'C';}}; A*p=new B; p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
A
B
B बी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B inherits A::f(). Output: A.
व्याख्या (हिन्दी) B को A::f() विरासत में मिला है। आउटपुट: ए.
871–885 of 1915