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
1756
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.
व्याख्या (हिन्दी) सी::एफ()=सी, बी::एफ()=बी, ए::एफ()=ए। आउटपुट: सीबीए.
1757
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()। आउटपुट: बी.
1758
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.
1759
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.
1760
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। कुल: एबीएसी.
1761
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.
1762
EN + हिं
1763
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.
1764
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.
1765
EN + हिं
GB What is the output: class A{public:virtual int f(int x=1){return x*2;}}; class B:public A{public:int f(int x=2)override{return x*3;}}; A*p=new B; cout<f();
IN आउटपुट क्या है: class A{public:virtual int f(int x=1){return x*2;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f(int x=2)ओवरराइड{रिटर्न x*3;}}; ए*पी=नया बी; अदालत
A
6 6
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Default args from static type (A*): x=1. B::f(1)=1*3=3. Output: 3.
व्याख्या (हिन्दी) स्थिर प्रकार (ए*) से डिफ़ॉल्ट तर्क: x=1। बी::एफ(1)=1*3=3. आउटपुट: 3.
1766
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} virtual void f(int){cout<<'X';}}; class B:public A{public:void f()override{cout<<'B';}}; A*p=new B; p->f(); p->f(1);
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
BX बीएक्स
B
BA बी ० ए
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f(): B::f()=B; p->f(1): A::f(int)=X. Output: BX.
व्याख्या (हिन्दी) p->f(): B::f()=B; p->f(1): A::f(int)=X. आउटपुट: बीएक्स.
1767
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;} void g(){f(); A::f();}}; B b; b.g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
21 21
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f()=2; A::f()=1. Output: 21.
व्याख्या (हिन्दी) एफ()=2; ए::एफ()=1. आउटपुट: 21.
1768
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';}}; class B:public A{public:virtual void f(){cout<<'B';}}; class C:public B{public:void f()override{cout<<'C';}}; A*p=new C; B*q=dynamic_cast(p); q->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
C सी
B
B बी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) q is B* pointing to C. q->f() virtual: C::f()=C. Output: C.
व्याख्या (हिन्दी) q, B* है जो C की ओर इशारा करता है। q->f() आभासी: C::f()=C। आउटपुट: सी.
1769
EN + हिं
GB What is the output: class A{public:virtual int f()=0; int g(){return f()*2;}}; class B:public A{public:int f()override{return 7;}}; A*p=new B; cout<g();
IN आउटपुट क्या है: class A{public:virtual int f()=0; int g(){रिटर्न f()*2;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f()ओवरराइड{वापसी 7;}}; ए*पी=नया बी; अदालत
A
14 14
B
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f()=7; g()=7*2=14. Output: 14.
व्याख्या (हिन्दी) बी::एफ()=7; जी()=7*2=14. आउटपुट: 14.
1770
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()final{cout<<2;}}; A*p=new B; p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
2 2
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) final prevents further override but is still virtual. p->f()=B::f()=2. Output: 2.
व्याख्या (हिन्दी) फाइनल आगे ओवरराइड को रोकता है लेकिन फिर भी आभासी है। p->f()=B::f()=2. आउटपुट: 2.
1756–1770 of 1915