OOP Using C++ — MCQ Practice

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

📚 107 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
107 questions
31
EN + हिं
GB What is 'cohesion' in OOP?
IN OOP में 'सामंजस्य' क्या है?
A
Degree to which class members relate to single purpose वह डिग्री जिससे वर्ग के सदस्य एकल उद्देश्य से संबंधित हों
B
Coupling between classes कक्षाओं के बीच युग्मन
C
Inheritance depth विरासत की गहराई
D
Number of methods विधियों की संख्या
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) High cohesion means a class has one clear, well-defined responsibility — a good encapsulation quality.
व्याख्या (हिन्दी) उच्च सामंजस्य का मतलब है कि एक वर्ग की एक स्पष्ट, अच्छी तरह से परिभाषित जिम्मेदारी है - एक अच्छी एनकैप्सुलेशन गुणवत्ता।
32
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.
33
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.
34
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.
व्याख्या (हिन्दी) पीआईएमपीएल कार्यान्वयन विवरण छुपाता है; इम्प्लांट बदलने से हेडर नहीं बदलता; ग्राहकों को पुनः संकलन की आवश्यकता नहीं है।
35
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.
36
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.
37
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.
व्याख्या (हिन्दी) अच्छा एनकैप्सुलेशन स्थिर सार्वजनिक इंटरफ़ेस को परिवर्तनशील निजी कार्यान्वयन से अलग करता है।
38
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.
39
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.
40
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.
व्याख्या (हिन्दी) कॉन्स्ट ऑब्जेक्ट पर नॉन-कॉन्स्ट फ़ंक्शन को कॉल करना एक संकलन त्रुटि है।
41
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.
व्याख्या (हिन्दी) कॉन्स्ट ऑब्जेक्ट पर नॉन-कॉन्स्ट फ़ंक्शन को कॉल करना एक संकलन त्रुटि है।
42
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.
43
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.
44
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} bool operator==(const A& o)const{return x==o.x;} bool operator!=(const A& o)const{return !(*this==o);}}; A a(3),b(3),c(4); cout<<(a==b)<<(a!=c);
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} bool ऑपरेटर==(const A& o)const{return x==o.x;} बूल ऑपरेटर!=(const A& o)const{return !(*this==o);}}; ए ए(3),बी(3),सी(4); अदालत
A
11 11
B
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) 3==3=1, 3!=4=1. Output: 11.
व्याख्या (हिन्दी) 3==3=1, 3!=4=1. आउटपुट: 11.
45
EN + हिं
GB What is the output: class A{int x=0; public: class B{A& a; public: B(A& a):a(a){} void f(){a.x=10;}}; int get()const{return x;}}; A a; A::B b(a); b.f(); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: वर्ग बी{ए&ए; सार्वजनिक: B(A& a):a(a){} void f(){a.x=10;}}; int get()const{return x;}}; ए ए; ए::बी बी(ए); बी.एफ(); अदालत
A
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) In C++11+, nested class has access to outer's private members. a.x=10. Output: 10.
व्याख्या (हिन्दी) C++11+ में, नेस्टेड क्लास के पास बाहरी निजी सदस्यों तक पहुंच होती है। a.x=10. आउटपुट: 10.
31–45 of 107