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
46
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; class B:public A{public:void f(){cout<<'B';}}; A*arr[2]={new B,new B}; for(auto p:arr) p->f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() {काउट
A
BB बी बी
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
AA
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Both B::f(). Output: BB.
व्याख्या (हिन्दी) दोनों B::f(). आउटपुट: बीबी.
47
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 call(A a){a.f();} B b; call(b);
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
1 1
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) call takes A by value — slices b. a.f()=A::f()=1. Output: 1.
व्याख्या (हिन्दी) कॉल ए को मान के आधार पर लेती है - स्लाइस बी। a.f()=A::f()=1. आउटपुट: 1.
48
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();}}; A*p=new B; p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
BA बी ० ए
B
AB अब
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f()=B, then A::f()=A. Output: BA.
व्याख्या (हिन्दी) बी::एफ()=बी, फिर ए::एफ()=ए। आउटपुट: बी.ए.
49
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} virtual int get(){return x;}}; class B:public A{int y; public: B(int a,int b):A(a),y(b){} int get()override{return A::get()+y;}}; A*p=new B(3,4); cout<get();
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} वर्चुअल int get(){return x;}}; कक्षा बी:सार्वजनिक ए{इंट वाई; सार्वजनिक: B(int a,int b):A(a),y(b){} int get()override{return A::get()+y;}}; ए*पी=नया बी(3,4); अदालत
A
7 7
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+4=7. Output: 7.
व्याख्या (हिन्दी) 3+4=7. आउटपुट: 7.
50
EN + हिं
GB What is the output: class A{public:virtual void f()=0; virtual void g(){f();}}; class B:public A{public:void f()override{cout<<'B';}}; B b; b.g();
IN आउटपुट क्या है: class A{public:virtual void f()=0; आभासी शून्य g(){f();}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() ओवरराइड {काउट
A
B बी
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
A
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() calls virtual f(): B::f()=B. Output: B.
व्याख्या (हिन्दी) g() वर्चुअल f() को कॉल करता है: B::f()=B। आउटपुट: बी.
51
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} }; class B:public A{}; class C:public A{}; B b; C c; A*arr[]={&b,&c}; for(auto p:arr) p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
AA
B
BC ईसा पूर्व
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Both inherit A::f(). Output: AA.
व्याख्या (हिन्दी) दोनों को A::f() विरासत में मिला है। आउटपुट: एए.
52
EN + हिं
GB What is 'virtual dispatch performance cost'?
IN 'वर्चुअल डिस्पैच प्रदर्शन लागत' क्या है?
A
Indirect call via vptr; possible cache miss; cannot inline वीपीटीआर के माध्यम से अप्रत्यक्ष कॉल; संभावित कैश मिस; इनलाइन नहीं कर सकते
B
No overhead कोई उपरिव्यय नहीं
C
Same as direct call सीधी कॉल के समान
D
Compile-time resolution संकलन-समय संकल्प
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Virtual calls require pointer dereference + table lookup; prevent inlining; may cause branch misprediction.
व्याख्या (हिन्दी) वर्चुअल कॉल के लिए पॉइंटर डीरेफ़रेंस + टेबल लुकअप की आवश्यकता होती है; इनलाइनिंग को रोकें; शाखा का गलत पूर्वानुमान हो सकता है.
53
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 a; B b; A*p=&a; p->f(); p=&b; p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
12 12
B
11 11
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f(): A::f()=1; p=&b; p->f(): B::f()=2. Output: 12.
व्याख्या (हिन्दी) p->f(): A::f()=1; पी=&बी; p->f(): B::f()=2. आउटपुट: 12.
54
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';}}; B b; b.g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
GB जीबी
B
GA गा
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() prints G then calls virtual f(): B::f()=B. Output: GB.
व्याख्या (हिन्दी) g() G को प्रिंट करता है फिर वर्चुअल f() को कॉल करता है: B::f()=B। आउटपुट: जीबी.
55
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; A *p=new struct B:public A{void f(){cout<<'X';}}{};p->f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; A *p=नई संरचना B:सार्वजनिक A{void f(){cout
A
X एक्स
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Inline struct definition inside new expression is not valid C++ syntax. Compile error.
व्याख्या (हिन्दी) नई अभिव्यक्ति के अंदर इनलाइन संरचना परिभाषा मान्य C++ सिंटैक्स नहीं है। संकलन त्रुटि.
56
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;} virtual void g(){cout<<2;} virtual void h(){cout<<3;}}; class B:public A{public:void g()override{cout<<4;}}; A*p=new B; p->f(); p->g(); p->h();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
142 142
B
124 124
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f()=A::f()=1; p->g()=B::g()=4; p->h()=A::h()=2... wait h()=3. Output: 143.
व्याख्या (हिन्दी) p->f()=A::f()=1; p->g()=B::g()=4; p->h()=A::h()=2... प्रतीक्षा करें h()=3. आउटपुट: 143.
57
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;}}; function funcs[]={[]{B().f();},{[]{C().f();}}}; for(auto&fn:funcs) fn();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
23 23
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B().f()=2(non-virtual on value); C().f()=3. Output: 23.
व्याख्या (हिन्दी) B().f()=2(मूल्य पर गैर-आभासी); सी().एफ()=3. आउटपुट: 23.
58
EN + हिं
GB What is the output: class A{public:virtual int f(int x){return x;}}; class B:public A{public:int f(int x)override{return x*2;}}; class C:public B{public:int f(int x)override{return x*3;}}; A *p=new C; cout<f(5);
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ(इंट x){रिटर्न x;}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: int f (int x) ओवरराइड {वापसी x * 2;}}; कक्षा सी:सार्वजनिक बी{सार्वजनिक:int f(int x)ओवरराइड{रिटर्न x*3;}}; ए *पी=नया सी; अदालत
A
15 15
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C::f(5)=15. Output: 15.
व्याख्या (हिन्दी) सी::एफ(5)=15. आउटपुट: 15.
59
EN + हिं
60
EN + हिं
46–60 of 94