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
31
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} void g(){f();}}; class B:public A{public:void f()override{cout<<'B';}}; A a; B b; a.g(); b.g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
AB अब
B
AA
C
BB बी बी
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) a.g(): A::g calls virtual f: A::f=A. b.g(): B inherits g; virtual f: B::f=B. Output: AB.
व्याख्या (हिन्दी) a.g(): A::g वर्चुअल f को कॉल करता है: A::f=A। b.g(): B को g विरासत में मिला है; आभासी एफ: बी::एफ=बी। आउटपुट: एबी.
32
EN + हिं
33
EN + हिं
34
EN + हिं
GB What is 'static_cast downcast' vs 'dynamic_cast'?
IN 'स्टैटिक_कास्ट डाउनकास्ट' बनाम 'डायनामिक_कास्ट' क्या है?
A
static_cast: unchecked; dynamic_cast: checked at runtime स्टेटिक_कास्ट: अनियंत्रित; डायनामिक_कास्ट: रनटाइम पर जाँच की गई
B
Same thing एक ही बात
C
static_cast is slower static_cast धीमा है
D
dynamic_cast is compile-time डायनामिक_कास्ट संकलन-समय है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) static_cast downcasting is UB if wrong type; dynamic_cast returns nullptr/throws on wrong type.
व्याख्या (हिन्दी) यदि गलत प्रकार है तो static_cast डाउनकास्टिंग यूबी है; डायनामिक_कास्ट nullptr लौटाता है/गलत प्रकार पर फेंकता है।
35
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 obj=B(); obj.f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
1 1
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A obj=B() slices B; obj is A. obj.f()=A::f()=1. Output: 1.
व्याख्या (हिन्दी) एक obj=B() स्लाइस B; obj A है. obj.f()=A::f()=1. आउटपुट: 1.
36
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 &r=*new B; r.f(); delete &r;
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
B बी
B
A
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) r.f() virtual dispatch: B::f(). Output: B.
व्याख्या (हिन्दी) r.f() वर्चुअल प्रेषण: B::f()। आउटपुट: बी.
37
EN + हिं
GB What is the output: class Shape{public:virtual double area()=0;}; class Rect:public Shape{double w,h; public:Rect(double a,double b):w(a),h(b){} double area(){return w*h;}}; Shape*s=new Rect(3,4); cout<area();
IN आउटपुट क्या है: क्लास शेप{पब्लिक:वर्चुअल डबल एरिया()=0;}; क्लास रेक्ट:पब्लिक शेप{डबल डब्ल्यू,एच; सार्वजनिक: रेक्ट (डबल ए, डबल बी): डब्ल्यू (ए), एच (बी) {} डबल एरिया() {रिटर्न डब्ल्यू * एच;}}; आकार*s=नया रेक्ट(3,4); अदालत
A
12 12
B
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3*4=12. Output: 12.
व्याख्या (हिन्दी) 3*4=12. आउटपुट: 12.
38
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;} void g(){cout<<2;}}; class B:public A{public:void f()override{cout<<3;} void g(){cout<<4;}}; A*p=new B; p->f(); p->g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
32 32
B
34 34
C
12 12
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f(): virtual: B::f()=3; p->g(): static: A::g()=2. Output: 32.
व्याख्या (हिन्दी) p->f(): आभासी: B::f()=3; p->g(): स्थिर: A::g()=2. आउटपुट: 32.
39
EN + हिं
GB What is the output: class A{public:virtual string name(){return "A";}}; class B:public A{public:string name()override{return "B";}}; class C:public B{public:string name()override{return "C";}}; A*p=new C; cout<name();
IN आउटपुट क्या है: क्लास ए{सार्वजनिक:वर्चुअल स्ट्रिंग नाम(){रिटर्न "ए";}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:स्ट्रिंग नाम()ओवरराइड{वापसी "बी";}}; कक्षा सी:सार्वजनिक बी{सार्वजनिक:स्ट्रिंग नाम()ओवरराइड{वापसी "सी";}}; ए*पी=नया सी; अदालत
A
C सी
B
A
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C::name(). Output: C.
व्याख्या (हिन्दी) सी::नाम(). आउटपुट: सी.
40
EN + हिं
GB What is 'virtual function table pointer (vptr)'?
IN 'वर्चुअल फंक्शन टेबल पॉइंटर (वीपीटीआर)' क्या है?
A
Pointer in each polymorphic object to its class vtable प्रत्येक बहुरूपी वस्तु में उसके वर्ग vtable के लिए सूचक
B
A static variable एक स्थिर चर
C
A function pointer array एक फ़ंक्शन सूचक सरणी
D
A compiler macro एक कंपाइलर मैक्रो
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) vptr is automatically added by compiler; points to vtable with function pointers for virtual functions.
व्याख्या (हिन्दी) वीपीटीआर स्वचालित रूप से कंपाइलर द्वारा जोड़ा जाता है; वर्चुअल फ़ंक्शंस के लिए फ़ंक्शन पॉइंटर्स के साथ vtable को इंगित करता है।
41
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(){A::f(); f();}}; B b; b.g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
12 12
B
22 22
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A::f()=1; f()=B::f()=2. Output: 12.
व्याख्या (हिन्दी) ए::एफ()=1; एफ()=बी::एफ()=2. आउटपुट: 12.
42
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';}}; class B:public A{}; class C:public B{public:void f()override{cout<<'C';}}; A*p=new C; p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
C सी
B
A
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C::f() overrides A::f(). Output: C.
व्याख्या (हिन्दी) C::f() A::f() को ओवरराइड करता है। आउटपुट: सी.
43
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} virtual void g(){cout<<'G';}}; class B:public A{public:void f()override{cout<<'B';} using A::g;}; A*p=new B; p->f(); p->g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
BG बीजी
B
BA बी ० ए
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f()=B::f()=B; p->g()=A::g()=G. Output: BG.
व्याख्या (हिन्दी) p->f()=B::f()=B; p->g()=A::g()=G. आउटपुट: बीजी.
44
EN + हिं
GB What is the output: class A{public:virtual int f(){return 0;}}; class B:public A{int x; public:B(int v):x(v){} int f()override{return x;}}; A*p=new B(99); cout<f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ(){रिटर्न 0;}}; कक्षा बी:सार्वजनिक ए{int x; सार्वजनिक:बी(int v):x(v){} int f()ओवरराइड{रिटर्न x;}}; ए*पी=नया बी(99); अदालत
A
99 99
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f()=x=99. Output: 99.
व्याख्या (हिन्दी) बी::f()=x=99. आउटपुट: 99.
45
EN + हिं
GB What is 'dynamic_cast to void*'?
IN 'डायनामिक_कास्ट टू वॉयड*' ​​क्या है?
A
Returns pointer to most-derived object सर्वाधिक-व्युत्पन्न ऑब्जेक्ट पर पॉइंटर लौटाता है
B
Returns null शून्य लौटाता है
C
Same as static_cast स्टेटिक_कास्ट के समान
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) dynamic_cast(ptr) returns pointer to the complete most-derived object.
व्याख्या (हिन्दी) डायनामिक_कास्ट(पीटीआर) संपूर्ण सर्वाधिक-व्युत्पन्न ऑब्जेक्ट पर पॉइंटर लौटाता है।
31–45 of 94