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
46
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.
47
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 के रूप में पहुंच योग्य बनाया जा सकता है। बी.एफ()=ए. आउटपुट: ए.
48
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.
49
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. आउटपुट: बी.ए.
50
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.
51
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.
52
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() को कॉल करता है। आउटपुट: ए.
53
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.
54
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.
55
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.
व्याख्या (हिन्दी) यदि बेस क्लास खाली है, तो व्युत्पन्न वस्तु को बड़ा होने की आवश्यकता नहीं है; ईबीओ शून्य ओवरहेड की अनुमति देता है।
56
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() विरासत में मिला है। आउटपुट: ए.
57
EN + हिं
GB What is the output: class A{public:int x=1;}; class B:virtual public A{public:int y=2;}; class C:virtual public A{public:int z=3;}; class D:public B,public C{}; D d; cout<
IN आउटपुट क्या है: class A{public:int x=1;}; क्लास बी:वर्चुअल पब्लिक ए{पब्लिक:इंट वाई=2;}; कक्षा सी:वर्चुअल पब्लिक ए{सार्वजनिक:int z=3;}; कक्षा डी:सार्वजनिक बी,सार्वजनिक सी{}; डी डी; अदालत
A
123 123
B
112 112
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Single A: x=1. y=2,z=3. Output: 123.
व्याख्या (हिन्दी) एकल ए: x=1. y=2,z=3. आउटपुट: 123.
58
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 a=B(); a.f(); a.g();
IN आउटपुट क्या है: कक्षा ए {सार्वजनिक: शून्य एफ() {काउट
A
Aa
B
Bb बी बी
C
AB अब
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A object (sliced): a.f()=non-virtual=A; a.g()=virtual but object is A type=a. Output: Aa.
व्याख्या (हिन्दी) एक वस्तु (कटी हुई): a.f()=non-virtual=A; a.g()=आभासी लेकिन वस्तु A प्रकार=a है। आउटपुट: आ.
59
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(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(5); A*q=p->clone(); cout<x;
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} वर्चुअल A* क्लोन(){वापसी नया A(*this);}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: बी (int v): ए (v) {} बी * क्लोन() ओवरराइड {नया बी लौटाएं (* यह);}}; ए*पी=नया बी(5); A*q=p->क्लोन(); अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::clone returns new B(5). q->x=5. Output: 5.
व्याख्या (हिन्दी) बी::क्लोन नया बी(5) लौटाता है। q->x=5. आउटपुट: 5.
60
EN + हिं
GB What is the output: class A{public:int x=0; void f(){x++; cout<
IN आउटपुट क्या है: class A{public:int x=0; शून्य f(){x++; अदालत
A
11 11
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b and c each have own x=0. b.f(): x=1, print 1. c.f(): x=1, print 1. Output: 11.
व्याख्या (हिन्दी) b और c प्रत्येक का अपना x=0 है। b.f(): x=1, प्रिंट 1. c.f(): x=1, प्रिंट 1. आउटपुट: 11.
46–60 of 104