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
31
EN + हिं
GB What is the output: class A{public:void f(){cout<<'A';}}; class B:public A{public:void f(){cout<<'B';}}; B b; b.f(); b.A::f();
IN आउटपुट क्या है: कक्षा ए {सार्वजनिक: शून्य एफ() {काउट
A
BA बी ० ए
B
AB अब
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b.f()=B, b.A::f()=A. Output: BA.
व्याख्या (हिन्दी) b.f()=B, b.A::f()=A. आउटपुट: बी.ए.
32
EN + हिं
GB What is the output: class A{public:int x=1;}; class B:public A{public:int y=2;}; B b; cout<
IN आउटपुट क्या है: class A{public:int x=1;}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int y=2;}; बी बी; अदालत
A
12 12
B
21 21
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b.x=1 (from A), b.y=2. Output: 12.
व्याख्या (हिन्दी) b.x=1 (ए से), b.y=2. आउटपुट: 12.
33
EN + हिं
34
EN + हिं
GB What is the output: class A{protected:int x=10;}; class B:public A{public:void show(){cout<
IN आउटपुट क्या है: class A{protected:int x=10;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य शो() {काउट
A
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=10 accessible in B. Output: 10.
व्याख्या (हिन्दी) x=10 बी में पहुंच योग्य। आउटपुट: 10।
35
EN + हिं
GB What is the output: class A{public:A(int){cout<<'A';}}; class B:public A{public:B():A(5){cout<<'B';}}; B b;
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए (इंट) {काउट
A
AB अब
B
BA बी ० ए
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A(5) first=A, then B=B. Output: AB.
व्याख्या (हिन्दी) ए(5) पहले=ए, फिर बी=बी। आउटपुट: एबी.
36
EN + हिं
GB What is 'virtual inheritance' use case?
IN 'वर्चुअल इनहेरिटेंस' उपयोग मामला क्या है?
A
Diamond: ensure single base subobject हीरा: एकल आधार उपवस्तु सुनिश्चित करें
B
Performance optimization प्रदर्शन अनुकूलन
C
Multiple return types एकाधिक रिटर्न प्रकार
D
Template specialization टेम्पलेट विशेषज्ञता
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) class B:virtual public A{}; class C:virtual public A{}; class D:public B,C{}; D has one A.
व्याख्या (हिन्दी) कक्षा बी:वर्चुअल पब्लिक ए{}; क्लास सी:वर्चुअल पब्लिक ए{}; कक्षा डी:सार्वजनिक बी,सी{}; D के पास एक A है.
37
EN + हिं
GB What is the output: class A{public:virtual int f(){return 1;}}; class B:public A{public:int f()override{return 2;}}; class C:public B{public:int f()override{return 3;}}; A*p=new C; cout<f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ(){रिटर्न 1;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f()ओवरराइड{वापसी 2;}}; कक्षा सी:सार्वजनिक बी{सार्वजनिक:int f()ओवरराइड{वापसी 3;}}; ए*पी=नया सी; अदालत
A
3 3
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C::f() is most derived. Output: 3.
व्याख्या (हिन्दी) C::f() सबसे अधिक व्युत्पन्न है। आउटपुट: 3.
38
EN + हिं
GB What is the output: class A{public:void f(){cout<<1;}}; class B:public A{public:void f(){cout<<2;} void g(){A::f(); f();}}; B b; b.g();
IN आउटपुट क्या है: कक्षा ए {सार्वजनिक: शून्य एफ() {काउट
A
12 12
B
21 21
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A::f()=1; f()=B::f()=2. Output: 12.
व्याख्या (हिन्दी) ए::एफ()=1; एफ()=बी::एफ()=2. आउटपुट: 12.
39
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){}}; class B:public A{public:int y; B(int a,int b):A(a),y(b){}}; B b(3,4); cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int y; B(int a,int b):A(a),y(b){}}; बी बी(3,4); अदालत
A
34 34
B
43 43
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=3,y=4. Output: 34.
व्याख्या (हिन्दी) x=3,y=4. आउटपुट: 34.
40
EN + हिं
GB What is the output: class A{public:static void f(){cout<<'S';}}; class B:public A{}; B::f();
IN आउटपुट क्या है: वर्ग ए {सार्वजनिक: स्थिर शून्य एफ() {काउट
A
S एस
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B inherits A::f. B::f()=S. Output: S.
व्याख्या (हिन्दी) B को A::f विरासत में मिला है। बी::एफ()=एस। आउटपुट: एस.
41
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';}}; class B:public A{public:void f()final{cout<<'B';}}; B b; b.f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
B बी
B
A
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b.f() calls B::f()=B. Output: B.
व्याख्या (हिन्दी) b.f() कॉल B::f()=B. आउटपुट: बी.
42
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.
व्याख्या (हिन्दी) ओवरराइडिंग से आधार के रिटर्न प्रकार का व्युत्पन्न सूचक/संदर्भ वापस आ सकता है।
43
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.
44
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() को भेजता है। आउटपुट: बी.
45
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.
31–45 of 104