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
916
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; A *p=new struct B:public A{void f(){cout<<'X';}}{};p->f();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; A *p=नई संरचना B:सार्वजनिक A{void f(){cout
A
X एक्स
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Inline struct definition inside new expression is not valid C++ syntax. Compile error.
व्याख्या (हिन्दी) नई अभिव्यक्ति के अंदर इनलाइन संरचना परिभाषा मान्य C++ सिंटैक्स नहीं है। संकलन त्रुटि.
917
EN + हिं
GB What is the output: class A{public:virtual void f(){cout<<1;} virtual void g(){cout<<2;} virtual void h(){cout<<3;}}; class B:public A{public:void g()override{cout<<4;}}; A*p=new B; p->f(); p->g(); p->h();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
142 142
B
124 124
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) p->f()=A::f()=1; p->g()=B::g()=4; p->h()=A::h()=2... wait h()=3. Output: 143.
व्याख्या (हिन्दी) p->f()=A::f()=1; p->g()=B::g()=4; p->h()=A::h()=2... प्रतीक्षा करें h()=3. आउटपुट: 143.
918
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 A{public:void f()override{cout<<3;}}; function funcs[]={[]{B().f();},{[]{C().f();}}}; for(auto&fn:funcs) fn();
IN आउटपुट क्या है: क्लास ए {पब्लिक: वर्चुअल शून्य एफ() {काउट
A
23 23
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B().f()=2(non-virtual on value); C().f()=3. Output: 23.
व्याख्या (हिन्दी) B().f()=2(मूल्य पर गैर-आभासी); सी().एफ()=3. आउटपुट: 23.
919
EN + हिं
GB What is the output: class A{int x=5; public: int get()const{return x;}}; A a; cout<
IN आउटपुट क्या है: class A{int x=5; सार्वजनिक: int get()const{return x;}}; ए ए; अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) get()=5. Output: 5.
व्याख्या (हिन्दी) प्राप्त करें()=5. आउटपुट: 5.
920
EN + हिं
GB What is the output: class A{int x; public: A(int v=0):x(v){} void inc(){x++;} int get()const{return x;}}; A a(10); for(int i=0;i<5;i++) a.inc(); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v=0):x(v){} void inc(){x++;} int get()const{return x;}}; ए ए(10); for(int i=0;i
A
15 15
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 10+5=15. Output: 15.
व्याख्या (हिन्दी) 10+5=15. आउटपुट: 15.
921
EN + हिं
GB What is 'PIMPL' benefit for compilation?
IN संकलन के लिए 'पीआईएमपीएल' लाभ क्या है?
A
Implementation changes don't require recompiling users कार्यान्वयन परिवर्तनों के लिए उपयोगकर्ताओं को पुनः संकलित करने की आवश्यकता नहीं है
B
Faster runtime तेज़ रनटाइम
C
Thread safety धागे की सुरक्षा
D
ABI stability एबीआई स्थिरता
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) PIMPL hides implementation details; changing impl doesn't change header; clients don't need recompile.
व्याख्या (हिन्दी) पीआईएमपीएल कार्यान्वयन विवरण छुपाता है; इम्प्लांट बदलने से हेडर नहीं बदलता; ग्राहकों को पुनः संकलन की आवश्यकता नहीं है।
922
EN + हिं
GB What is the output: class A{int x=0; public: void set(int v){if(v>=0) x=v;} int get()const{return x;}}; A a; a.set(-5); a.set(3); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: शून्य सेट(int v){if(v>=0) x=v;} int get()const{return x;}}; ए ए; ए.सेट(-5); ए.सेट(3); अदालत
A
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) -5 rejected; 3 accepted. x=3. Output: 3.
व्याख्या (हिन्दी) -5 अस्वीकृत; 3 स्वीकृत. एक्स=3. आउटपुट: 3.
923
EN + हिं
GB What is the output: class A{int x; public: A():x(42){} int& ref(){return x;}}; A a; cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A():x(42){} int& ref(){return x;}}; ए ए; अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) ref()=x=42. Output: 42.
व्याख्या (हिन्दी) रेफरी()=x=42. आउटपुट: 42.
924
EN + हिं
GB What is 'interface' vs 'implementation' in encapsulation?
IN इनकैप्सुलेशन में 'इंटरफ़ेस' बनाम 'कार्यान्वयन' क्या है?
A
Interface: what client uses; implementation: how it works इंटरफ़ेस: ग्राहक क्या उपयोग करता है; कार्यान्वयन: यह कैसे काम करता है
B
Same thing एक ही बात
C
Both public दोनों सार्वजनिक
D
Both private दोनों निजी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Good encapsulation separates stable public interface from changeable private implementation.
व्याख्या (हिन्दी) अच्छा एनकैप्सुलेशन स्थिर सार्वजनिक इंटरफ़ेस को परिवर्तनशील निजी कार्यान्वयन से अलग करता है।
925
EN + हिं
GB What is the output: class A{int x=0,y=0; public: void move(int dx,int dy){x+=dx;y+=dy;} int getX()const{return x;} int getY()const{return y;}}; A a; a.move(3,4); a.move(-1,2); cout<
IN आउटपुट क्या है: class A{int x=0,y=0; सार्वजनिक: शून्य चाल(int dx,int dy){x+=dx;y+=dy;} int getX()const{return x;} int getY()const{return y;}}; ए ए; ए.हटो(3,4); ए.मूव(-1,2); अदालत
A
26 26
B
34 34
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=0+3-1=2, y=0+4+2=6. Output: 26.
व्याख्या (हिन्दी) x=0+3-1=2, y=0+4+2=6. आउटपुट: 26.
926
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} int getX()const{return x;} A operator+(const A& o)const{return A(x+o.x);}}; A a(3),b(4); cout<<(a+b).getX();
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} int getX()const{return x;} A ऑपरेटर+(const A& o)const{return A(x+o.x);}}; ए ए(3),बी(4); अदालत
A
7 7
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3+4=7. Output: 7.
व्याख्या (हिन्दी) 3+4=7. आउटपुट: 7.
927
EN + हिं
GB What is the output: class Counter{int n=0; public: void inc(){n++;} void dec(){n (1, 6, 82, 12, 4, 'What is 'const member function' and const object?
IN आउटपुट क्या है: क्लास काउंटर{int n=0; सार्वजनिक: void inc(){n++;} void dec(){n (1, 6, 82, 12, 4, 'कॉन्स्ट मेंबर फ़ंक्शन' और कॉन्स्ट ऑब्जेक्ट क्या है?
A
const object can only call const member functions कॉन्स्ट ऑब्जेक्ट केवल कॉन्स्ट सदस्य फ़ंक्शंस को कॉल कर सकता है
B
const function can modify data कॉन्स्ट फ़ंक्शन डेटा को संशोधित कर सकता है
C
All functions are const by default सभी फ़ंक्शन डिफ़ॉल्ट रूप से स्थिरांक हैं
D
Compile error if const संकलित त्रुटि यदि const
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Calling non-const function on const object is a compile error.
व्याख्या (हिन्दी) कॉन्स्ट ऑब्जेक्ट पर नॉन-कॉन्स्ट फ़ंक्शन को कॉल करना एक संकलन त्रुटि है।
928
EN + हिं
GB What is 'const member function' and const object?
IN 'कॉन्स्ट मेंबर फ़ंक्शन' और कॉन्स्ट ऑब्जेक्ट क्या है?
A
const object can only call const member functions कॉन्स्ट ऑब्जेक्ट केवल कॉन्स्ट सदस्य फ़ंक्शंस को कॉल कर सकता है
B
const function can modify data कॉन्स्ट फ़ंक्शन डेटा को संशोधित कर सकता है
C
All functions are const by default सभी फ़ंक्शन डिफ़ॉल्ट रूप से स्थिरांक हैं
D
Compile error if const संकलित त्रुटि यदि const
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Calling non-const function on const object is a compile error.
व्याख्या (हिन्दी) कॉन्स्ट ऑब्जेक्ट पर नॉन-कॉन्स्ट फ़ंक्शन को कॉल करना एक संकलन त्रुटि है।
929
EN + हिं
GB What is the output: class A{mutable int c=0; public: int get()const{return ++c;}}; const A a; cout<
IN आउटपुट क्या है: class A{mutable int c=0; सार्वजनिक: int get()const{return++c;}}; स्थिरांक ए ए; अदालत
A
12 12
B
11 11
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) mutable allows modification in const function. c: 1 then 2. Output: 12.
व्याख्या (हिन्दी) म्यूटेबल कॉन्स्ट फ़ंक्शन में संशोधन की अनुमति देता है। सी: 1 फिर 2. आउटपुट: 12.
930
EN + हिं
GB What is the output: class A{int x=0; public: void f(A& o){o.x=5;} int get()const{return x;}}; A a,b; a.f(b); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: void f(A& o){o.x=5;} int get()const{return x;}}; ए ए, बी; ए.एफ(बी); अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Member functions can access private members of any instance of same class. b.x=5. Output: 5.
व्याख्या (हिन्दी) सदस्य फ़ंक्शन उसी वर्ग के किसी भी उदाहरण के निजी सदस्यों तक पहुंच सकते हैं। बी.एक्स=5. आउटपुट: 5.
916–930 of 1915