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
1
EN + हिं
GB What is encapsulation?
IN एनकैप्सुलेशन क्या है?
A
Bundling data and methods, controlling access डेटा और विधियों को बंडल करना, पहुंच को नियंत्रित करना
B
Hiding implementation in header हेडर में कार्यान्वयन छुपाया जा रहा है
C
Making all members private सभी सदस्यों को निजी बनाना
D
Using namespaces नामस्थानों का उपयोग करना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Encapsulation combines data and methods in a class and controls access via access specifiers.
व्याख्या (हिन्दी) एनकैप्सुलेशन एक क्लास में डेटा और विधियों को जोड़ता है और एक्सेस स्पेसिफायर के माध्यम से एक्सेस को नियंत्रित करता है।
2
EN + हिं
GB What is the output: class A{int x=42; public: int get()const{return x;}}; A a; cout<
IN आउटपुट क्या है: class A{int x=42; सार्वजनिक: int get()const{return x;}}; ए ए; अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x is private but get() is public and returns x=42. Output: 42.
व्याख्या (हिन्दी) x निजी है लेकिन get() सार्वजनिक है और x=42 लौटाता है। आउटपुट: 42.
3
EN + हिं
GB What does 'const' member function guarantee?
IN 'कॉन्स्ट' सदस्य फ़ंक्शन क्या गारंटी देता है?
A
Doesn't modify non-mutable data members गैर-परिवर्तनीय डेटा सदस्यों को संशोधित नहीं करता है
B
Immutable object अपरिवर्तनीय वस्तु
C
Thread-safe function थ्रेड-सुरक्षित फ़ंक्शन
D
Inline function इनलाइन फ़ंक्शन
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A const member function cannot modify data members (except mutable ones) and can be called on const objects.
व्याख्या (हिन्दी) एक कॉन्स्ट मेंबर फ़ंक्शन डेटा सदस्यों (म्यूटेबल को छोड़कर) को संशोधित नहीं कर सकता है और इसे कॉन्स्ट ऑब्जेक्ट पर कॉल किया जा सकता है।
4
EN + हिं
GB What is the output: class A{public: int x; void setX(int v){x=v;} int getX(){return x;}}; A a; a.setX(10); cout<
IN आउटपुट क्या है: क्लास ए {सार्वजनिक: int x; void setX(int v){x=v;} int getX(){return x;}}; ए ए; ए.सेटएक्स(10); अदालत
A
10 10
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) setX(10) sets x=10, getX() returns x=10. Output: 10.
व्याख्या (हिन्दी) setX(10) x=10 सेट करता है, getX() x=10 लौटाता है। आउटपुट: 10.
5
EN + हिं
GB What is 'information hiding'?
IN 'जानकारी छिपाना' क्या है?
A
Hiding implementation details from users उपयोगकर्ताओं से कार्यान्वयन विवरण छिपाना
B
Runtime data hiding रनटाइम डेटा छिपाना
C
Encryption कूटलेखन
D
Namespace hiding नेमस्पेस छिपाना
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Information hiding prevents direct access to implementation details, exposing only necessary interface.
व्याख्या (हिन्दी) सूचना छिपाना कार्यान्वयन विवरण तक सीधी पहुंच को रोकता है, केवल आवश्यक इंटरफ़ेस को उजागर करता है।
6
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.
7
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.
व्याख्या (हिन्दी) गेटर्स निजी डेटा सदस्यों को सीधे उजागर किए बिना उन्हें पढ़ने की पहुंच प्रदान करते हैं।
8
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.
व्याख्या (हिन्दी) डेटा अमूर्तन आवश्यक विशेषताओं को उजागर करता है; डेटा छिपाने से आंतरिक विवरण छिप जाते हैं - संबंधित लेकिन विशिष्ट अवधारणाएँ।
9
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.
10
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.
11
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.
व्याख्या (हिन्दी) एक वर्ग अपरिवर्तनीय एक तार्किक स्थिति है जो वर्ग के प्रत्येक वैध उदाहरण के लिए हमेशा सत्य होती है।
12
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. नोट: यह एनकैप्सुलेशन को तोड़ता है।
13
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).
व्याख्या (हिन्दी) अपारदर्शी प्रकार कार्यान्वयन विवरणों को छिपाने, युग्मन को कम करने (पीआईएमपीएल मुहावरे) के लिए आगे की घोषणाओं का उपयोग करते हैं।
14
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.
15
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 (पॉइंटर टू इम्प्लीमेंटेशन) एक निजी पॉइंटर का उपयोग एक इम्प्लांट संरचना में करता है, कार्यान्वयन को छुपाता है और संकलन निर्भरता को कम करता है।
1–15 of 107