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
76
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 B{};A*p=new C;p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
2 2
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C inherits B::f(). p->f()=2. Output: 2.
व्याख्या (हिन्दी) C को B::f() विरासत में मिला है। p->f()=2. आउटपुट: 2.
77
EN + हिं
GB What is the output: class A{public:int x=10; virtual int f(){return x;}}; class B:public A{public:B(){x=20;} int f()override{return x*2;}}; A*p=new B; cout<f();
IN आउटपुट क्या है: class A{public:int x=10; वर्चुअल int f(){रिटर्न x;}}; क्लास बी:पब्लिक ए{पब्लिक:बी(){x=20;} int f()ओवरराइड{रिटर्न x*2;}}; ए*पी=नया बी; अदालत
A
40 40
B
20 20
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B() sets x=20. B::f()=20*2=40. Output: 40.
व्याख्या (हिन्दी) बी() x=20 सेट करता है। बी::एफ()=20*2=40। आउटपुट: 40.
78
EN + हिं
GB What is the output: class A{public:virtual void f()=0; int g(){return 42;}}; class B:public A{public:void f()override{cout<
IN आउटपुट क्या है: class A{public:virtual void f()=0; int g(){वापसी 42;}}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() ओवरराइड {काउट
A
42 42
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f() calls A::g()=42. Output: 42.
व्याख्या (हिन्दी) B::f() A::g()=42 को कॉल करता है। आउटपुट: 42.
79
EN + हिं
GB What is the output: class A{public:int x=5;}; class B:public A{}; class C:public B{}; C c; cout<
IN आउटपुट क्या है: class A{public:int x=5;}; कक्षा बी:सार्वजनिक ए{}; कक्षा सी:सार्वजनिक बी{}; सी सी; अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) c.x inherited from A. Output: 5.
व्याख्या (हिन्दी) c.x ए से विरासत में मिला है। आउटपुट: 5।
80
EN + हिं
GB What is the output: class A{public:A(int v){cout<
IN आउटपुट क्या है: क्लास ए {पब्लिक: ए (इंट वी) {काउट
A
123 123
B
321 321
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A(1)=1, B=2, C=3. Output: 123.
व्याख्या (हिन्दी) ए(1)=1, बी=2, सी=3। आउटपुट: 123.
81
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} virtual void g(){f();}}; class B:public A{public:void f()override{cout<<'B';}}; B b; b.g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
B बी
B
A
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) g() calls virtual f(): B::f()=B. Output: B.
व्याख्या (हिन्दी) g() वर्चुअल f() को कॉल करता है: B::f()=B। आउटपुट: बी.
82
EN + हिं
GB What is the output: class A{public:int x=1; virtual int f(){return x;}}; class B:public A{public:int f()override{return x+1;}}; class C:public B{public:int f()override{return x+2;}}; A a; B b; C c; cout<
IN आउटपुट क्या है: class A{public:int x=1; वर्चुअल int f(){रिटर्न x;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f()ओवरराइड{वापसी x+1;}}; कक्षा सी:सार्वजनिक बी{सार्वजनिक:int f()ओवरराइड{वापसी x+2;}}; ए ए; बी बी; सी सी; अदालत
A
123 123
B
111 111
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A::f()=1, B::f()=2, C::f()=3. Output: 123.
व्याख्या (हिन्दी) ए::एफ()=1, बी::एफ()=2, सी::एफ()=3। आउटपुट: 123.
83
EN + हिं
GB 'What is the output: class A{public:static int n; A(){n++;} ~A(){n (1, 6, 80, 10, 4, 'What is the output: class A{public:int x; A(int v):x(v){}}; class B:virtual public A{public:B():A(1){}}; class C:virtual public A{public:C():A(2){}}; class D:public B
IN 'आउटपुट क्या है: क्लास ए{पब्लिक:स्टैटिक इंट एन; A(){n++;} ~A(){n (1, 6, 80, 10, 4, 'आउटपुट क्या है: क्लास ए{पब्लिक:इंट एक्स; ए(इंट वी):एक्स(वी){}}; क्लास बी:वर्चुअल पब्लिक ए{पब्लिक:बी():ए(1){}}; क्लास सी:वर्चुअल पब्लिक ए{पब्लिक:सी():ए(2){}}; क्लास डी:पब्लिक बी
A
B() बी()
B
3 3
C
1 1
D
Compile error संकलन त्रुटि
✅ Correct Answer:
84
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){}}; class B:virtual public A{public:B():A(1){}}; class C:virtual public A{public:C():A(2){}}; class D:public B,public C{public:D():A(3),B(),C(){}}; D d; cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){}}; क्लास बी:वर्चुअल पब्लिक ए{पब्लिक:बी():ए(1){}}; क्लास सी:वर्चुअल पब्लिक ए{पब्लिक:सी():ए(2){}}; कक्षा डी:सार्वजनिक बी,सार्वजनिक सी{सार्वजनिक:डी():ए(3),बी(),सी(){}}; डी डी; अदालत
A
3 3
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Most derived class D initializes virtual base A(3). x=3. Output: 3.
व्याख्या (हिन्दी) अधिकांश व्युत्पन्न वर्ग डी आभासी आधार ए(3) को आरंभ करता है। एक्स=3. आउटपुट: 3.
85
EN + हिं
GB What is the output: class A{public:void f(){cout<<'A';}}; class B:private A{public: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 f public in B. b.f()=A::f()=A. Output: A.
व्याख्या (हिन्दी) A::f का उपयोग करने से B में f सार्वजनिक हो जाता है। b.f()=A::f()=A। आउटपुट: ए.
86
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(); B *q=(B*)p; q->f(); q->g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
3234 3234
B
1234 1234
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f()=3(virtual); p->g()=2(non-virtual A); q->f()=3(virtual); q->g()=4(non-virtual B). Output: 3234.
व्याख्या (हिन्दी) p->f()=3(आभासी); p->g()=2(गैर-आभासी A); q->f()=3(आभासी); q->g()=4(गैर-आभासी B). आउटपुट: 3234.
87
EN + हिं
GB What is the output: class A{public:int x=0; virtual void inc(){x++;}}; class B:public A{public:void inc()override{x+=2;}}; A *p=new B; p->inc(); p->inc(); cout<x;
IN आउटपुट क्या है: class A{public:int x=0; आभासी शून्य इंक(){x++;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:शून्य इंक()ओवरराइड{x+=2;}}; ए *पी=नया बी; p->inc(); p->inc(); अदालत
A
4 4
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Each inc() adds 2. 2+2=4. Output: 4.
व्याख्या (हिन्दी) प्रत्येक inc() 2 जोड़ता है। 2+2=4। आउटपुट: 4.
88
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;} int f(){return 3;}}; const A*p=new B; cout<f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ()कॉन्स्ट{रिटर्न 1;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f()const ओवरराइड{रिटर्न 2;} int f(){रिटर्न 3;}}; स्थिरांक ए*पी=नया बी; अदालत
A
2 2
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p is const A*; virtual const f(); dispatches to B::f()const=2. Output: 2.
व्याख्या (हिन्दी) p स्थिरांक A* है; आभासी स्थिरांक f(); B::f()const=2 को भेजता है। आउटपुट: 2.
89
EN + हिं
GB What is the output: class A{public:int x; A(int v):x(v){} A(const A&o)=default;}; class B:public A{public:int y; B(int a,int b):A(a),y(b){}}; B b(3,4); B c=b; cout<
IN आउटपुट क्या है: class A{public:int x; A(int v):x(v){} A(const A&o)=default;}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int y; B(int a,int b):A(a),y(b){}}; बी बी(3,4); बी सी=बी; अदालत
A
34 34
B
00 00
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Default copy ctor copies all: c.x=3,c.y=4. Output: 34.
व्याख्या (हिन्दी) डिफ़ॉल्ट कॉपी ctor सभी कॉपी करता है: c.x=3,c.y=4. आउटपुट: 34.
90
EN + हिं
GB What is the output: class Shape{public:virtual double area()=0; double perimeter(){return 0;}}; class Sq:public Shape{double s; public:Sq(double v):s(v){} double area()override{return s*s;}}; Sq sq(5); cout<
IN आउटपुट क्या है: क्लास शेप{पब्लिक:वर्चुअल डबल एरिया()=0; दोहरा परिधि(){वापसी 0;}}; वर्ग वर्ग:सार्वजनिक आकार{डबल एस; सार्वजनिक: वर्ग (डबल वी): एस (वी) {} डबल एरिया() ओवरराइड {रिटर्न एस * एस;}}; वर्ग वर्ग(5); अदालत
A
25 25
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5*5=25. Output: 25.
व्याख्या (हिन्दी) 5*5=25. आउटपुट: 25.
76–90 of 104