OOP Using C++ — MCQ Practice

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

📚 1915 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
1915 questions
886
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.
887
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 है। आउटपुट: आ.
888
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.
889
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.
890
EN + हिं
GB What is the output: class A{public:virtual int f()const{return 1;}}; class B:public A{public:int f()const override{return 2;}}; const A *p=new B; cout<f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ()कॉन्स्ट{रिटर्न 1;}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: int f() स्थिरांक ओवरराइड {वापसी 2;}}; स्थिरांक ए *पी=नया बी; अदालत
A
2 2
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f() virtual dispatch: B::f()=2. Output: 2.
व्याख्या (हिन्दी) p->f() आभासी प्रेषण: B::f()=2। आउटपुट: 2.
891
EN + हिं
GB What is the output: class A{public:virtual int f(){return 1;}}; class B:public A{public:int f()override{return 2;}}; A *p=new B; cout<f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ(){रिटर्न 1;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f()ओवरराइड{वापसी 2;}}; ए *पी=नया बी; अदालत
A
2 2
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f(). Output: 2.
व्याख्या (हिन्दी) बी::एफ(). आउटपुट: 2.
892
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 विरासत में मिला है; आभासी एफ: बी::एफ=बी। आउटपुट: एबी.
893
EN + हिं
894
EN + हिं
895
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 लौटाता है/गलत प्रकार पर फेंकता है।
896
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.
897
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()। आउटपुट: बी.
898
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.
899
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.
900
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.
व्याख्या (हिन्दी) सी::नाम(). आउटपुट: सी.
886–900 of 1915