OOP Using C++ — MCQ Practice

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

📚 101 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
101 questions
46
EN + हिं
GB What is the output: class Observable{vector> obs; public: void subscribe(function f){obs.push_back(f);} void notify(){for(auto& f:obs) f();}}; Observable o; int x=0; o.subscribe([&]{x++;}); o.subscribe([&]{x+=2;}); o.notify(); cout<
IN आउटपुट क्या है: क्लास ऑब्जर्वेबल{वेक्टर ऑब्स; सार्वजनिक: शून्य सदस्यता(फ़ंक्शन f){obs.push_back(f);} शून्य सूचित(){for(auto& f:obs) f();}}; देखने योग्य ओ; int x=0; o.सदस्यता लें([&]{x++;}); o.सदस्यता लें([&]{x+=2;}); o.सूचित करें(); अदालत
A
3 3
B
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x+=1+2=3. Output: 3.
व्याख्या (हिन्दी) x+=1+2=3. आउटपुट: 3.
47
EN + हिं
GB What is the output: class Transformer{public:virtual int transform(int x)=0;}; class Double:public Transformer{public:int transform(int x)override{return x*2;}}; class Inc:public Transformer{public:int transform(int x)override{return x+1;}}; vector ts={new Double,new Inc}; int val=5; for(auto t:ts) val=t->transform(val); cout<
IN आउटपुट क्या है: क्लास ट्रांसफार्मर {सार्वजनिक: वर्चुअल इंट ट्रांसफॉर्म (इंट x) = 0;}; क्लास डबल:पब्लिक ट्रांसफार्मर{पब्लिक:इंट ट्रांसफॉर्म(इंट x)ओवरराइड{रिटर्न x*2;}}; क्लास इंक:पब्लिक ट्रांसफार्मर{पब्लिक:इंट ट्रांसफॉर्म(इंट एक्स)ओवरराइड{रिटर्न x+1;}}; वेक्टर ts={नया डबल,नया इंक}; int वैल=5; for(auto t:ts) val=t->transform(val); अदालत
A
11 11
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5*2=10, 10+1=11. Output: 11.
व्याख्या (हिन्दी) 5*2=10, 10+1=11. आउटपुट: 11.
48
EN + हिं
GB What is the output: class Singleton{static Singleton* inst; Singleton(){} public: static Singleton* get(){if(!inst) inst=new Singleton; return inst;} int x=42;}; Singleton* Singleton::inst=nullptr; cout<x;
IN आउटपुट क्या है: वर्ग सिंगलटन{स्थैतिक सिंगलटन* inst; सिंगलटन(){} सार्वजनिक: स्थिर सिंगलटन* get(){if(!inst) inst=new सिंगलटन; वापसी inst;} int x=42;}; सिंगलटन* सिंगलटन::inst=nullptr; अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) First call creates instance; x=42. Output: 42.
व्याख्या (हिन्दी) पहली कॉल उदाहरण बनाती है; एक्स=42. आउटपुट: 42.
49
EN + हिं
GB What is the output: class A{public:virtual void f()=0; virtual ~A()=default;}; auto factory=[](int t)->A*{struct B:A{void f(){cout<<1;}}; struct C:A{void f(){cout<<2;}}; return t?new C:new B;}; auto p=factory(0); p->f();
IN आउटपुट क्या है: class A{public:virtual void f()=0; आभासी ~ए()=डिफ़ॉल्ट;}; ऑटो फ़ैक्टरी=[](int t)->A*{struct B:A{void f(){cout
A
1 1
B
2 2
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) t=0: returns B; B::f()=1. Output: 1.
व्याख्या (हिन्दी) t=0: रिटर्न बी; बी::एफ()=1. आउटपुट: 1.
50
EN + हिं
GB What is the output: template int sumAll(const Container& c){int s=0;for(int x:c)s+=x;return s;} vectorv={1,2,3,4,5}; cout<
IN आउटपुट क्या है: template int sumAll(const Container& c){int s=0;for(int x:c)s+=x;return s;} वेक्टरv={1,2,3,4,5}; अदालत
A
15 15
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 1+2+3+4+5=15. Output: 15.
व्याख्या (हिन्दी) 1+2+3+4+5=15. आउटपुट: 15.
51
EN + हिं
GB What is the output: class Decorator{function f; public: Decorator(function fn):f(fn){} Decorator add(function g){return {[=](int x){return g(f(x));}};} int call(int x){return f(x);}}; Decorator d{[](int x){return x*2;}}; auto d2=d.add([](int x){return x+1;}); cout<
IN आउटपुट क्या है: क्लास डेकोरेटर{फ़ंक्शन f; सार्वजनिक: डेकोरेटर(फ़ंक्शन fn):f(fn){} डेकोरेटर ऐड(फ़ंक्शन g){रिटर्न {[=](int x){रिटर्न g(f(x));}};} int कॉल(int x){रिटर्न f(x);}}; डेकोरेटर d{[](int x){रिटर्न x*2;}}; ऑटो d2=d.add([](int x){रिटर्न x+1;}); अदालत
A
11 11
B
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 5*2=10, 10+1=11. Output: 11.
व्याख्या (हिन्दी) 5*2=10, 10+1=11. आउटपुट: 11.
52
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; class B:public A{public:void f()override{cout<
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() ओवरराइड {काउट
A
1B 1बी
B
B बी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) typeid(*this).name() on GCC for B: typically '1B'. Impl-defined. Generally prints type name.
व्याख्या (हिन्दी) B के लिए GCC पर typeid(*this).name(): आमतौर पर '1B'। इम्प्लांट-परिभाषित। आम तौर पर नाम प्रकार प्रिंट करता है।
53
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; try{A *p=new struct B:A{void f(){}}{};delete p;}catch(...){} cout<<'X';
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; प्रयास करें{A *p=नई संरचना B:A{void f(){}}{};delete p;}catch(...){} cout
A
Compile error संकलन त्रुटि
B
X एक्स
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Inline struct definition in new is not valid C++. Compile error.
व्याख्या (हिन्दी) नई में इनलाइन संरचना परिभाषा मान्य C++ नहीं है। संकलन त्रुटि.
54
EN + हिं
GB What is the output: class Memo{mapm; public: int f(int n){if(m.count(n))return m[n]; return m[n]=n<=1?n:f(n-1)+f(n-2);}}; Memo memo; cout<
IN आउटपुट क्या है: क्लास मेमो{मैपम; सार्वजनिक: int f(int n){if(m.count(n))रिटर्न m[n]; वापसी एम[एन]=एन
A
55 55
B
34 34
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Fib(10)=55. Output: 55.
व्याख्या (हिन्दी) फ़िब(10)=55. आउटपुट: 55.
55
EN + हिं
GB What is the output: class Builder{int x=0,y=0; public: Builder& setX(int v){x=v;return *this;} Builder& setY(int v){y=v;return *this;} int build(){return x+y;}}; cout<
IN आउटपुट क्या है: क्लास बिल्डर{int x=0,y=0; सार्वजनिक: Builder& setX(int v){x=v;return *this;} Builder& setY(int v){y=v;return *this;} int build(){return x+y;}}; अदालत
A
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+4=7. Output: 7.
व्याख्या (हिन्दी) 3+4=7. आउटपुट: 7.
56
EN + हिं
GB What is the output: class A{public:virtual int f()const=0;}; class B:public A{int v; public:B(int v):v(v){} int f()const override{return v*v;}}; vector> v; v.push_back(make_unique(3)); v.push_back(make_unique(4)); int s=0; for(auto&p:v)s+=p->f(); cout<
IN आउटपुट क्या है: class A{public:virtual int f()const=0;}; कक्षा बी:सार्वजनिक ए{इंट वी; सार्वजनिक:बी(int v):v(v){} int f()const ओवरराइड{रिटर्न v*v;}}; वेक्टर वी; v.push_back(make_unique(3)); v.push_back(make_unique(4)); int s=0; for(auto&p:v)s+=p->f(); अदालत
A
25 25
B
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 9+16=25. Output: 25.
व्याख्या (हिन्दी) 9+16=25. आउटपुट: 25.
57
EN + हिं
GB What is the output: class Pipe{vector>fns; public: Pipe& add(functionf){fns.push_back(f);return *this;} int run(int x){for(auto&f:fns)x=f(x);return x;}}; Pipe p; p.add([](int x){return x*2;}).add([](int x){return x+3;}).add([](int x){return x*x;}); cout<
IN आउटपुट क्या है: class Pipe{vectorfns; सार्वजनिक: Pipe& add(functionf){fns.push_back(f);return *this;} int run(int x){for(auto&f:fns)x=f(x);return x;}}; पाइप पी; p.add([](int x){return x*2;}).add([](int x){return x+3;}).add([](int x){return x*x;}); अदालत
A
169 169
B
100 100
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) (5*2+3)^2=(10+3)^2=169. Output: 169.
व्याख्या (हिन्दी) (5*2+3)^2=(10+3)^2=169. आउटपुट: 169.
58
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; class B:public A{public:void f()override{cout<<'B';}}; class C:public A{public:void f()override{cout<<'C';}}; map> m; m["b"]=make_unique(); m["c"]=make_unique(); for(auto&[k,v]:m) v->f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() ओवरराइड {काउट
A
BC ईसा पूर्व
B
CB सीबी
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) map ordered: b
व्याख्या (हिन्दी) मानचित्र का आदेश दिया गया: बी
59
EN + हिं
GB What is 'interface segregation principle' in C++?
IN C++ में 'इंटरफ़ेस पृथक्करण सिद्धांत' क्या है?
A
Split large interfaces into smaller specific ones बड़े इंटरफ़ेस को छोटे विशिष्ट इंटरफ़ेस में विभाजित करें
B
Combine all interfaces सभी इंटरफ़ेस को संयोजित करें
C
Use only abstract classes केवल अमूर्त वर्गों का प्रयोग करें
D
PIMPL pattern पीआईएमपीएल पैटर्न
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) ISP: clients depend only on interfaces they use; prevents fat interfaces with unused methods.
व्याख्या (हिन्दी) आईएसपी: ग्राहक केवल उनके द्वारा उपयोग किए जाने वाले इंटरफेस पर निर्भर करते हैं; अप्रयुक्त तरीकों से वसा इंटरफेस को रोकता है।
60
EN + हिं
46–60 of 101