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
91
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} virtual ~A()=default;}; class B:public A{public:void f()override{cout<<'B';}}; class C:public A{public:void f()override{cout<<'C';}}; auto v=vector>{}; v.push_back(make_unique()); v.push_back(make_unique()); v.push_back(make_unique()); for(auto&p:v) p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
BCB बीसीबी
B
ABC एबीसी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B,C,B. Output: BCB.
व्याख्या (हिन्दी) बी,सी,बी. आउटपुट: बीसीबी.
92
EN + हिं
GB What is the output: class A{protected:int x; public:A(int v):x(v){}}; class B:public A{public:B(int v):A(v){} int f(){return x*x;}}; B b(5); cout<
IN आउटपुट क्या है: class A{protected:int x; सार्वजनिक:ए(int v):x(v){}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: बी (int v): ए (v) {} int f() {वापसी x*x;}}; बी बी(5); अदालत
A
25 25
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=5; x*x=25. Output: 25.
व्याख्या (हिन्दी) एक्स=5; x*x=25. आउटपुट: 25.
93
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; class B:public A{public:void f()override{cout<<1;}}; auto fp=&B::f; B b; (b.*fp)();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() ओवरराइड {काउट
A
1 1
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) fp is pointer to B::f. (b.*fp)()=1. Output: 1.
व्याख्या (हिन्दी) fp B::f का सूचक है। (बी.*एफपी)()=1. आउटपुट: 1.
94
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;} void g(){A::f();}}; B b; b.g(); cout<
IN आउटपुट क्या है: class A{public:int x=0; आभासी शून्य f(){x=1;}}; वर्ग बी:सार्वजनिक ए{सार्वजनिक:शून्य एफ()ओवरराइड{x=2;} शून्य जी(){ए::एफ();}}; बी बी; b.g(); अदालत
A
1 1
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b.g() calls A::f() explicitly: x=1. Output: 1.
व्याख्या (हिन्दी) b.g() स्पष्ट रूप से A::f() को कॉल करता है: x=1। आउटपुट: 1.
95
EN + हिं
GB What is the output: class A{public:int x; A(int v=0):x(v){}}; class B:public A{public:B(int v):A(v*2){}}; class C:public B{public:C(int v):B(v+1){}}; C c(2); cout<
IN आउटपुट क्या है: class A{public:int x; A(int v=0):x(v){}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:बी(int v):ए(v*2){}}; कक्षा सी:सार्वजनिक बी{सार्वजनिक:सी(int v):बी(v+1){}}; सी सी(2); अदालत
A
6 6
B
4 4
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C(2): B(3): A(6). x=6. Output: 6.
व्याख्या (हिन्दी) सी(2): बी(3): ए(6)। एक्स=6. आउटपुट: 6.
96
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::f();}}; class C:public B{public:void f()override{cout<<'C'; B::f();}}; C c; c.f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
CBA सीबीए
B
ABC एबीसी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C::f()=C, B::f()=B, A::f()=A. Output: CBA.
व्याख्या (हिन्दी) सी::एफ()=सी, बी::एफ()=बी, ए::एफ()=ए। आउटपुट: सीबीए.
97
EN + हिं
GB What is the output: class A{public:virtual void show(){cout<<"A";}}; class B:public A{public:void show()override{cout<<"B";}}; void print(A& a){a.show();} B b; print(b);
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड शो(){काउट
A
B बी
B
A
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.show() virtual: B::show(). Output: B.
व्याख्या (हिन्दी) a.show() वर्चुअल: B::show()। आउटपुट: बी.
98
EN + हिं
GB What is the output: class A{public:int n; A(int v):n(v){} virtual A* clone(){return new A(*this);}}; class B:public A{public:B(int v):A(v){} B* clone()override{return new B(*this);}}; A *p=new B(42); A *q=p->clone(); cout<n;
IN आउटपुट क्या है: class A{public:int n; A(int v):n(v){} वर्चुअल A* क्लोन(){नया A(*this);}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: बी (int v): ए (v) {} बी * क्लोन() ओवरराइड {नया बी लौटाएं (* यह);}}; ए *पी=नया बी(42); A *q=p->क्लोन(); अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::clone() returns new B(42). q->n=42. Output: 42.
व्याख्या (हिन्दी) B::क्लोन() नया B(42) लौटाता है। q->n=42. आउटपुट: 42.
99
EN + हिं
GB What is the output: class A{public:int x=1;}; class B:public A{public:int x=2;}; B b; A& ra=b; B& rb=b; cout<
IN आउटपुट क्या है: class A{public:int x=1;}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int x=2;}; बी बी; ए&आरए=बी; बी&आरबी=बी; अदालत
A
12 12
B
22 22
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) ra.x=A::x=1; rb.x=B::x=2. Output: 12.
व्याख्या (हिन्दी) ra.x=A::x=1; rb.x=B::x=2. आउटपुट: 12.
100
EN + हिं
GB What is the output: class A{public:A(){cout<<'A';} A(const A&){cout<<'C';}};class B:public A{public:B():A(){cout<<'B';}};B b1;B b2=b1;
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए() {काउट
A
ABAC एबीएसी
B
ABBC एबीबीसी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b1: A(),B=AB. b2=b1: A(const A&)=C,B(implicit copy)=B... actually B's implicit copy calls A's copy: AC. Total: ABAC.
व्याख्या (हिन्दी) बी1: ए(),बी=एबी। b2=b1: A(const A&)=C,B(अंतर्निहित प्रतिलिपि)=B... वास्तव में B की अंतर्निहित प्रतिलिपि A की प्रतिलिपि को कॉल करती है: AC। कुल: एबीएसी.
101
EN + हिं
GB What is the output: struct A{int x=1; virtual void f(){x=2;}}; struct B:A{void f()override{x=3;}}; A a; B b; A& ra=a; B& rb=b; ra.f(); rb.f(); cout<
IN आउटपुट क्या है: struct A{int x=1; आभासी शून्य f(){x=2;}}; संरचना बी:ए{शून्य एफ()ओवरराइड{x=3;}}; ए ए; बी बी; ए&आरए=ए; बी&आरबी=बी; ra.f(); आरबी.एफ(); अदालत
A
23 23
B
22 22
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) ra.f(): A::f()=x=2. rb.f(): B::f()=x=3. Output: 23.
व्याख्या (हिन्दी) ra.f(): A::f()=x=2. rb.f(): B::f()=x=3. आउटपुट: 23.
102
EN + हिं
103
EN + हिं
GB What is the output: class A{public:int x=0; A(){} A(const A& o):x(o.x+10){}}; class B:public A{public:B(){x=5;}}; B b; A a=b; cout<
IN आउटपुट क्या है: class A{public:int x=0; A(){} A(const A& o):x(o.x+10){}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:बी(){x=5;}}; बी बी; ए ए=बी; अदालत
A
15 15
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Slicing: A's copy ctor called with B object (sliced to A). A::copy ctor: x=b.A::x+10=5+10=15... Wait: b.A::x=0 (A's default ctor runs first then B sets x=5). b.x (A part) = 5. A copy: x=5+10=15. Output: 15.
व्याख्या (हिन्दी) स्लाइसिंग: A की कॉपी ctor को B ऑब्जेक्ट के साथ बुलाया जाता है (A से स्लाइस किया गया)। A::copy ctor: x=b.A::x+10=5+10=15... प्रतीक्षा करें: b.A::x=0 (A का डिफ़ॉल्ट ctor पहले चलता है फिर B x=5 सेट करता है)। b.x (एक भाग) = 5. एक प्रति: x=5+10=15. आउटपुट: 15.
104
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* p=&b; p->f(); p->g(); b.f(); b.g();
IN आउटपुट क्या है: कक्षा ए {सार्वजनिक: शून्य एफ() {काउट
A
1434 1434
B
3434 3434
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f():static=1; p->g():virtual=4; b.f():static=3; b.g():static=4. Output: 1434.
व्याख्या (हिन्दी) p->f():static=1; p->g():आभासी=4; b.f():static=3; b.g():static=4. आउटपुट: 1434.
91–104 of 104