OOP Using C++ — MCQ Practice

Hindi aur English dono mein practice karo — click karo answer check karne ke liye

📚 94 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
94 questions
61
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2; A::f();}}; B b; b.f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
21 21
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f()=2; A::f()=1. Output: 21.
व्याख्या (हिन्दी) बी::एफ()=2; ए::एफ()=1. आउटपुट: 21.
62
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} void g(){cout<<'G'; f();}}; class B:public A{public:void f()override{cout<<'B';}}; A *p=new B; p->g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
GB जीबी
B
GA गा
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g()=G; virtual f()=B::f()=B. Output: GB.
व्याख्या (हिन्दी) जी()=जी; आभासी f()=B::f()=B. आउटपुट: जीबी.
63
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;}}; A *arr[]={new A,new B,new A,new B}; for(auto p:arr) p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
1212 1212
B
1111 1111
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A=1,B=2,A=1,B=2. Output: 1212.
व्याख्या (हिन्दी) ए=1,बी=2,ए=1,बी=2। आउटपुट: 1212.
64
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} virtual bool eq(const A& o)const{return x==o.x;}}; class B:public A{public:B(int v):A(v){} bool eq(const A& o)const override{return A::eq(o);}}; A *p=new B(5); A *q=new B(5); cout<eq(*q);
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} virtual bool eq(const A& o)const{return x==o.x;}}; क्लास बी:पब्लिक ए{पब्लिक:बी(इंट वी):ए(वी){} बूल ईक्यू(कॉन्स्ट ए&ओ)कॉन्स्ट ओवरराइड{रिटर्न ए::ईक्यू(ओ);}}; ए *पी=नया बी(5); ए *क्यू=नया बी(5); अदालत
A
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Both x=5: eq=1. Output: 1.
व्याख्या (हिन्दी) दोनों x=5: eq=1. आउटपुट: 1.
65
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} virtual void g(){cout<<'G';} void h(){f(); g();}}; class B:public A{public:void f()override{cout<<'B';}}; B b; b.h();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
BG बीजी
B
AG एजी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f()=B; A::g()=G. Output: BG.
व्याख्या (हिन्दी) बी::एफ()=बी; ए::जी()=जी. आउटपुट: बीजी.
66
EN + हिं
GB What is the output: class A{public:virtual int f(int x=10){return x;}}; class B:public A{public:int f(int x=20)override{return x*2;}}; A *p=new B; cout<f();
IN आउटपुट क्या है: कक्षा ए {सार्वजनिक: आभासी int f (int x = 10) {वापसी x;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f(int x=20)ओवरराइड{रिटर्न x*2;}}; ए *पी=नया बी; अदालत
A
20 20
B
40 40
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Default args resolved at static type (A*): x=10. B::f(10)=10*2=20. Output: 20.
व्याख्या (हिन्दी) स्थिर प्रकार (ए*) पर डिफ़ॉल्ट तर्क हल किए गए: x=10। बी::एफ(10)=10*2=20. आउटपुट: 20.
67
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;}}; class C:public A{public:void f()override{cout<<3;}}; auto v=vector{new B,new C,new B}; int s=0; for(auto p:v)p->f(); cout<<' '<
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
2 3 2 3 2 3 2 3
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
option_b विकल्प_बी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) See explanation.
व्याख्या (हिन्दी) स्पष्टीकरण देखें.
68
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.
69
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. आउटपुट: बीएक्स.
70
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.
71
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। आउटपुट: सी.
72
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.
73
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.
74
EN + हिं
75
EN + हिं
GB What is the output: class A{public:virtual ~A(){} virtual void f()=0;}; class B:public A{public:void f()override{cout<<'B';}}; class C:public A{public:void f()override{cout<<'C';}}; vectorv={new B,new C,new B,new C}; int n=0; for(auto p:v) {p->f(); if(dynamic_cast(p))n++;} cout<
IN आउटपुट क्या है: वर्ग A{सार्वजनिक:वर्चुअल ~A(){} वर्चुअल शून्य f()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() ओवरराइड {काउट
A
BCBC2 BCBC2
B
BCB2 बीसीबी2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B,C,B,C printed; 2 B's. Output: BCBC2.
व्याख्या (हिन्दी) बी,सी,बी,सी मुद्रित; 2 बी. आउटपुट: BCBC2.
61–75 of 94