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
76
EN + हिं
GB What is the output: class A{public:virtual int f(){return 1;} virtual int g(){return f()+1;}}; class B:public A{public:int f()override{return 2;}}; B b; cout<
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ(){रिटर्न 1;} वर्चुअल इंट जी(){रिटर्न एफ()+1;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f()ओवरराइड{वापसी 2;}}; बी बी; अदालत
A
3 3
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) b.g()=A::g()=f()+1=B::f()+1=2+1=3. Output: 3.
व्याख्या (हिन्दी) b.g()=A::g()=f()+1=B::f()+1=2+1=3. आउटपुट: 3.
77
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; struct B:A{void f()override{cout<<'B';}}; struct C:A{void f()override{cout<<'C';}}; auto apply=[](A& a){a.f();}; B b; C c; apply(b); apply(c);
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; संरचना बी:ए{शून्य एफ()ओवरराइड{काउट
A
BC ईसा पूर्व
B
CB सीबी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) apply(b)=B, apply(c)=C. Output: BC.
व्याख्या (हिन्दी) लागू करें (बी) = बी, लागू करें (सी) = सी। आउटपुट: बी.सी.
78
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 *arr[3]={new A,new B,new B}; for(auto p:arr)p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
122 122
B
111 111
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A=1,B=2,B=2. Output: 122.
व्याख्या (हिन्दी) ए=1,बी=2,बी=2. आउटपुट: 122.
79
EN + हिं
GB What is the output: class A{public:virtual int f(){return 1;}}; class B:public A{public:int f()override{return 2;}}; int apply(A* p,int n){int s=0;for(int i=0;i
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल इंट एफ(){रिटर्न 1;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f()ओवरराइड{वापसी 2;}}; int लागू(A* p,int n){int s=0;for(int i=0;i
A
3 3
B
6 6
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) arr[i] accessed as A; all A::f()=1. Sum=3. Output: 3.
व्याख्या (हिन्दी) arr[i] को A के रूप में एक्सेस किया गया; सभी A::f()=1. योग=3. आउटपुट: 3.
80
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* make(int t){return t?new B:new A;} for(int i=0;i<3;i++){auto*p=make(i%2);p->f();delete p;}
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
ABB एबीबी
B
ABA आबा
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) i=0:make(0)=A:A; i=1:make(1)=B:B; i=2:make(0)=A:A. Output: ABA.
व्याख्या (हिन्दी) i=0:make(0)=A:A; i=1:make(1)=B:B; i=2:make(0)=A:A. आउटपुट: एबीए.
81
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;}}; template void call(T* p){p->f();} A a; B b; call(&a); call(&b);
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
12 12
B
11 11
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
82
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} virtual void g()=0;}; class B:public A{public:void f()override{cout<<'B';} void g()override{cout<<'G';}}; B b; b.f(); b.g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
BG बीजी
B
AG एजी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f()=B; g()=G. Output: BG.
व्याख्या (हिन्दी) एफ()=बी; जी()=जी. आउटपुट: बीजी.
83
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+=5;}}; vectorv={new A,new B,new A}; for(auto p:v)p->inc(); int s=0; for(auto p:v)s+=p->x; cout<
IN आउटपुट क्या है: class A{public:int x=0; आभासी शून्य इंक(){x++;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:शून्य इंक()ओवरराइड{x+=5;}}; वेक्टरv={नया ए,नया बी,नया ए}; for(auto p:v)p->inc(); int s=0; for(auto p:v)s+=p->x; अदालत
A
7 7
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A.x=1; B.x=5; A.x=1. Sum=7. Output: 7.
व्याख्या (हिन्दी) A.x=1; बी.एक्स=5; ए.एक्स=1. योग=7. आउटपुट: 7.
84
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<'A';} void g(){f();cout<<'G';}}; class B:public A{public:void f()override{cout<<'B';}}; B b; b.g();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
BG बीजी
B
AG एजी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) f()=B::f()=B; then G. Output: BG.
व्याख्या (हिन्दी) f()=B::f()=B; फिर जी. आउटपुट: बीजी.
85
EN + हिं
86
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 bobj; A* ptrs[]={&obj,&bobj,&obj}; for(A*p:ptrs)p->f();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
121 121
B
111 111
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A=1,B=2,A=1. Output: 121.
व्याख्या (हिन्दी) ए=1,बी=2,ए=1. आउटपुट: 121.
87
EN + हिं
GB What is the output: class A{public:virtual string name(){return "A";} string greet(){return "Hi "+name();}}; class B:public A{public:string name()override{return "B";}}; B b; cout<
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल स्ट्रिंग नेम(){रिटर्न "ए";} स्ट्रिंग ग्रीट(){रिटर्न "हाय "+नेम();}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:स्ट्रिंग नाम()ओवरराइड{वापसी "बी";}}; बी बी; अदालत
A
Hi B हाय बी
B
Hi A हाय ए
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) greet() calls virtual name(): B::name()=B. Output: Hi B.
व्याख्या (हिन्दी) greet() वर्चुअल नाम() को कॉल करता है: B::name()=B। आउटपुट: हाय बी.
88
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;}}; class B:public A{public:void f()override{cout<<2;}}; functionfp=[](A*p){p->f();}; fp(new A); fp(new B);
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
12 12
B
11 11
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Virtual dispatch: 1,2. Output: 12.
व्याख्या (हिन्दी) आभासी प्रेषण: 1,2. आउटपुट: 12.
89
EN + हिं
GB What is the output: class A{public:virtual void f()=0; virtual ~A()=default;}; class B:public A{int x; public:B(int v):x(v){} void f()override{cout<>v; v.push_back(make_shared(5)); v.push_back(make_shared(10)); for(auto&p:v)p->f();
IN आउटपुट क्या है: class A{public:virtual void f()=0; आभासी ~ए()=डिफ़ॉल्ट;}; कक्षा बी:सार्वजनिक ए{int x; सार्वजनिक:B(int v):x(v){} void f()ओवरराइड{cout
A
510 510
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
5 10 5 10
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f() prints x. Output: 510.
व्याख्या (हिन्दी) B::f() x प्रिंट करता है। आउटपुट: 510.
90
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* p=new B; cout<
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
1B 1बी
B
1A 1 क
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) typeid(*p) with virtual = B's typeinfo. GCC: '1B'. Output: 1B.
व्याख्या (हिन्दी) टाइपआईडी(*पी) वर्चुअल = बी के टाइपइन्फो के साथ। जीसीसी: '1बी'. आउटपुट: 1बी.
76–90 of 94