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
346
EN + हिं
GB What is the output: class A{int x=5; public: void f(){x*=2;} int g()const{return x;}}; A a; a.f(); a.f(); cout<
IN आउटपुट क्या है: class A{int x=5; सार्वजनिक: void f(){x*=2;} int g()const{return x;}}; ए ए; a.f(); a.f(); अदालत
A
20 20
B
10 10
C
5 5
D
40 40
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Initial x=5. f() doubles: 5->10->20. g()=20. Output: 20.
व्याख्या (हिन्दी) प्रारंभिक x=5. f() दोगुना: 5->10->20। जी()=20. आउटपुट: 20.
347
EN + हिं
GB What is a 'getter' function?
IN 'गेटर' फ़ंक्शन क्या है?
A
Public function that returns value of private member सार्वजनिक फ़ंक्शन जो निजी सदस्य का मान लौटाता है
B
A constructor एक कंस्ट्रक्टर
C
A static function एक स्थिर कार्य
D
An accessor that modifies state एक एक्सेसर जो स्थिति को संशोधित करता है
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Getters provide read access to private data members without exposing them directly.
व्याख्या (हिन्दी) गेटर्स निजी डेटा सदस्यों को सीधे उजागर किए बिना उन्हें पढ़ने की पहुंच प्रदान करते हैं।
348
EN + हिं
GB What is 'data abstraction' vs 'data hiding'?
IN 'डेटा एब्स्ट्रैक्शन' बनाम 'डेटा छिपाना' क्या है?
A
Abstraction shows interface; hiding conceals implementation अमूर्तन इंटरफ़ेस दिखाता है; छिपाना कार्यान्वयन को छुपाता है
B
They are identical वे समान हैं
C
Hiding is compile-time; abstraction is runtime छिपाना संकलन-समय है; अमूर्तन रनटाइम है
D
Both are about inheritance दोनों विरासत के बारे में हैं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Data abstraction exposes essential features; data hiding conceals internal details — related but distinct concepts.
व्याख्या (हिन्दी) डेटा अमूर्तन आवश्यक विशेषताओं को उजागर करता है; डेटा छिपाने से आंतरिक विवरण छिप जाते हैं - संबंधित लेकिन विशिष्ट अवधारणाएँ।
349
EN + हिं
GB What is the output: class A{int x; public: A():x(0){} void inc(){x++;} bool isEven()const{return x%2==0;}}; A a; a.inc(); a.inc(); a.inc(); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A():x(0){} void inc(){x++;} bool isEven()const{return x%2==0;}}; ए ए; a.inc(); a.inc(); a.inc(); अदालत
A
1 1
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x starts 0, inc() three times: x=3. 3%2=1 ≠ 0, isEven()=false=0. Output: 0.
व्याख्या (हिन्दी) x 0 से प्रारंभ होता है, inc() तीन बार: x=3। 3%2=1 ≠ 0, सम()=असत्य=0। आउटपुट: 0.
350
EN + हिं
GB What is the output: class A{static int c; public: A(){c++;} static int count(){return c;}}; int A::c=0; A a,b,c; cout<
IN आउटपुट क्या है: class A{static int c; सार्वजनिक: A(){c++;} स्टेटिक इंट काउंट(){रिटर्न c;}}; int A::c=0; ए ए, बी, सी; अदालत
A
3 3
B
1 1
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Each construction increments c. 3 objects created, count()=3. Output: 3.
व्याख्या (हिन्दी) प्रत्येक निर्माण वृद्धि सी. 3 वस्तुएँ बनाई गईं, गिनती()=3। आउटपुट: 3.
351
EN + हिं
GB What is 'class invariant'?
IN 'वर्ग अपरिवर्तनीय' क्या है?
A
Condition always true for valid object state वैध वस्तु स्थिति के लिए शर्त हमेशा सत्य होती है
B
A constant member एक स्थायी सदस्य
C
A private constructor एक निजी कंस्ट्रक्टर
D
An assertion एक दावा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A class invariant is a logical condition that is always true for every valid instance of the class.
व्याख्या (हिन्दी) एक वर्ग अपरिवर्तनीय एक तार्किक स्थिति है जो वर्ग के प्रत्येक वैध उदाहरण के लिए हमेशा सत्य होती है।
352
EN + हिं
GB What is the output: class A{int x=10; public: int& ref(){return x;}}; A a; a.ref()=20; cout<
IN आउटपुट क्या है: class A{int x=10; सार्वजनिक: int& ref(){रिटर्न x;}}; ए ए; a.ref()=20; अदालत
A
10 10
B
20 20
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) ref() returns reference to private x. Assigning 20 modifies x. Output: 20. Note: this breaks encapsulation.
व्याख्या (हिन्दी) Ref() निजी x का संदर्भ लौटाता है। 20 असाइन करने से x संशोधित हो जाता है। आउटपुट: 20. नोट: यह एनकैप्सुलेशन को तोड़ता है।
353
EN + हिं
GB What is 'opaque type' in C++?
IN C++ में 'अपारदर्शी प्रकार' क्या है?
A
Type with hidden implementation (forward declaration only) छिपे हुए कार्यान्वयन के साथ टाइप करें (केवल आगे की घोषणा)
B
Virtual class आभासी कक्षा
C
POD type पीओडी प्रकार
D
Template type टेम्पलेट प्रकार
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Opaque types use forward declarations to hide implementation details, reducing coupling (PIMPL idiom).
व्याख्या (हिन्दी) अपारदर्शी प्रकार कार्यान्वयन विवरणों को छिपाने, युग्मन को कम करने (पीआईएमपीएल मुहावरे) के लिए आगे की घोषणाओं का उपयोग करते हैं।
354
EN + हिं
GB What is the output: class A{int x,y; public: A(int a,int b):x(a),y(b){} int sum()const{return x+y;}}; A a(3,4); cout<
IN आउटपुट क्या है: class A{int x,y; सार्वजनिक: A(int a,int b):x(a),y(b){} int sum()const{return x+y;}}; ए ए(3,4); अदालत
A
7 7
B
12 12
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=3, y=4, sum()=7. Output: 7.
व्याख्या (हिन्दी) x=3, y=4, योग()=7. आउटपुट: 7.
355
EN + हिं
GB What is 'PIMPL idiom'?
IN 'पीआईएमपीएल मुहावरा' क्या है?
A
Pointer to Implementation — hiding implementation in separate class कार्यान्वयन का सूचक - कार्यान्वयन को अलग वर्ग में छिपाना
B
Public Interface Multiple Polymorphism सार्वजनिक इंटरफ़ेस एकाधिक बहुरूपता
C
Pointer Inside Member Pattern Linkage पॉइंटर इनसाइड मेंबर पैटर्न लिंकेज
D
Private implementation with multiple inheritance एकाधिक वंशानुक्रम के साथ निजी कार्यान्वयन
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) PIMPL (Pointer to IMPLementation) uses a private pointer to an impl struct, hiding implementation and reducing compile dependencies.
व्याख्या (हिन्दी) PIMPL (पॉइंटर टू इम्प्लीमेंटेशन) एक निजी पॉइंटर का उपयोग एक इम्प्लांट संरचना में करता है, कार्यान्वयन को छुपाता है और संकलन निर्भरता को कम करता है।
356
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} operator int(){return x;}}; A a(5); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} ऑपरेटर int(){return x;}}; ए ए(5); अदालत
A
8 8
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) operator int() converts a to 5. 5+3=8. Output: 8.
व्याख्या (हिन्दी) ऑपरेटर int() a को 5 में परिवर्तित करता है। 5+3=8। आउटपुट: 8.
357
EN + हिं
GB What is 'access specifier' in C++?
IN C++ में 'एक्सेस स्पेसिफायर' क्या है?
A
public, protected, private — controls member visibility सार्वजनिक, संरक्षित, निजी - सदस्य दृश्यता को नियंत्रित करता है
B
const, volatile modifiers स्थिरांक, अस्थिर संशोधक
C
Virtual and override keywords वर्चुअल और ओवरराइड कीवर्ड
D
Static and extern keywords स्थैतिक और बाहरी कीवर्ड
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Access specifiers (public/protected/private) define which code can access class members.
व्याख्या (हिन्दी) एक्सेस स्पेसिफायर (सार्वजनिक/संरक्षित/निजी) परिभाषित करते हैं कि कौन सा कोड क्लास सदस्यों तक पहुंच सकता है।
358
EN + हिं
GB What is the output: class A{int x=0; public: A& operator++(){x++; return *this;} int get()const{return x;}}; A a; ++a; ++a; ++a; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: A& ऑपरेटर++(){x++; रिटर्न *यह;} int get()const{रिटर्न x;}}; ए ए; ++ए; ++ए; ++ए; अदालत
A
3 3
B
1 1
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Each prefix ++ increments x. After 3 calls, x=3. Output: 3.
व्याख्या (हिन्दी) प्रत्येक उपसर्ग ++ x को बढ़ाता है। 3 कॉल के बाद, x=3. आउटपुट: 3.
359
EN + हिं
GB What is 'const correctness'?
IN 'स्थिरांक शुद्धता' क्या है?
A
Using const wherever possible to prevent unintended modification अनपेक्षित संशोधन को रोकने के लिए जहां भी संभव हो const का उपयोग करना
B
Making all methods const सभी विधियों को स्थिरांक बनाना
C
Immutable objects only केवल अपरिवर्तनीय वस्तुएँ
D
Const member initialization कॉन्स्ट सदस्य आरंभीकरण
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Const correctness means marking member functions const when they don't modify state, and const objects/references where appropriate.
व्याख्या (हिन्दी) कॉन्स्ट शुद्धता का मतलब है कि जब सदस्य फ़ंक्शन स्थिति को संशोधित नहीं करते हैं तो कॉन्स्ट को चिह्नित करना, और जहां उपयुक्त हो वहां कॉन्स्ट ऑब्जेक्ट/संदर्भों को चिह्नित करना।
360
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;}}; A a(5),b(5); cout<<(a==b);
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} bool ऑपरेटर==(const A&o)const{return x==o.x;}}; ए ए(5),बी(5); अदालत
A
1 1
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) operator== compares x values: 5==5=true=1. Output: 1.
व्याख्या (हिन्दी) ऑपरेटर== x मानों की तुलना करता है: 5==5=सही=1। आउटपुट: 1.
346–360 of 1915