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
16
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.
17
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.
व्याख्या (हिन्दी) एक्सेस स्पेसिफायर (सार्वजनिक/संरक्षित/निजी) परिभाषित करते हैं कि कौन सा कोड क्लास सदस्यों तक पहुंच सकता है।
18
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.
19
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.
व्याख्या (हिन्दी) कॉन्स्ट शुद्धता का मतलब है कि जब सदस्य फ़ंक्शन स्थिति को संशोधित नहीं करते हैं तो कॉन्स्ट को चिह्नित करना, और जहां उपयुक्त हो वहां कॉन्स्ट ऑब्जेक्ट/संदर्भों को चिह्नित करना।
20
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.
21
EN + हिं
GB What is the output: class A{int x=5; public: void print()const{cout<
IN आउटपुट क्या है: class A{int x=5; सार्वजनिक: शून्य प्रिंट() स्थिरांक {cout
A
5 5
B
10 10
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) const object can call const member functions. print() outputs x=5. Output: 5.
व्याख्या (हिन्दी) कॉन्स्ट ऑब्जेक्ट कॉन्स्ट सदस्य फ़ंक्शंस को कॉल कर सकता है। प्रिंट() आउटपुट x=5। आउटपुट: 5.
22
EN + हिं
GB What is 'interface segregation' and encapsulation?
IN 'इंटरफ़ेस पृथक्करण' और एनकैप्सुलेशन क्या है?
A
Many specific interfaces better than one general interface कई विशिष्ट इंटरफ़ेस एक सामान्य इंटरफ़ेस से बेहतर हैं
B
Hiding all members सभी सदस्यों को छुपाया जा रहा है
C
Using private inheritance निजी विरासत का उपयोग करना
D
Abstract base class only केवल सार आधार वर्ग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Interface segregation (ISP) means clients shouldn't depend on interfaces they don't use — relates to well-encapsulated design.
व्याख्या (हिन्दी) इंटरफ़ेस पृथक्करण (आईएसपी) का मतलब है कि ग्राहकों को उन इंटरफेस पर निर्भर नहीं रहना चाहिए जिनका वे उपयोग नहीं करते हैं - यह अच्छी तरह से इनकैप्सुलेटेड डिज़ाइन से संबंधित है।
23
EN + हिं
GB What is the output: class A{int x=0; public: int get()const{return x;} void set(int v){if(v>0) x=v;}}; A a; a.set(-5); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: int get()const{return x;} void set(int v){if(v>0) x=v;}}; ए ए; ए.सेट(-5); अदालत
B
-5 -5
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) set() validates: -5 is not >0, so x stays 0. get()=0. Output: 0.
व्याख्या (हिन्दी) सेट() मान्य करता है: -5 >0 नहीं है, इसलिए x 0 ही रहता है। get()=0। आउटपुट: 0.
24
EN + हिं
GB What is the output: class A{int x; public: A(int v=0):x(v){} int operator+(const A&o)const{return x+o.x;}}; A a(3),b(4); cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v=0):x(v){} int ऑपरेटर+(const A&o)const{return x+o.x;}}; ए ए(3),बी(4); अदालत
A
7 7
B
12 12
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) operator+ returns x+o.x = 3+4=7. Output: 7.
व्याख्या (हिन्दी) ऑपरेटर+ रिटर्न x+o.x = 3+4=7. आउटपुट: 7.
25
EN + हिं
GB What is 'friend class' in C++?
IN C++ में 'फ्रेंड क्लास' क्या है?
A
Class with access to another class's private/protected members किसी अन्य वर्ग के निजी/संरक्षित सदस्यों तक पहुंच वाला वर्ग
B
Derived class व्युत्पन्न वर्ग
C
Inner class आंतरिक वर्ग
D
Same-package class समान-पैकेज वर्ग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) A friend class declaration inside a class grants all of that friend class's methods access to private/protected members.
व्याख्या (हिन्दी) किसी वर्ग के अंदर एक मित्र वर्ग की घोषणा उस मित्र वर्ग के सभी तरीकों को निजी/संरक्षित सदस्यों तक पहुंच प्रदान करती है।
26
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} friend ostream& operator<<(ostream& os,const A& a){os<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} मित्र ओस्ट्रीम& ऑपरेटर
A
99 99
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Friend operator<< accesses private x=99. Output: 99.
व्याख्या (हिन्दी) मित्र संचालिका
27
EN + हिं
GB What is the purpose of making constructors private?
IN कंस्ट्रक्टर्स को निजी बनाने का उद्देश्य क्या है?
A
Singleton pattern — prevents direct instantiation सिंगलटन पैटर्न - प्रत्यक्ष इन्स्टेन्शियशन को रोकता है
B
Performance optimization प्रदर्शन अनुकूलन
C
Preventing inheritance वंशानुक्रम को रोकना
D
Abstract class creation सार वर्ग निर्माण
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Private constructors enforce patterns like Singleton, where object creation is controlled through a factory method.
व्याख्या (हिन्दी) निजी कंस्ट्रक्टर सिंगलटन जैसे पैटर्न लागू करते हैं, जहां ऑब्जेक्ट निर्माण को फ़ैक्टरी विधि के माध्यम से नियंत्रित किया जाता है।
28
EN + हिं
GB What is the output: class A{int x=1,y=2; public: int sum()const{return x+y;} void scale(int f){x*=f; y*=f;}}; A a; a.scale(3); cout<
IN आउटपुट क्या है: class A{int x=1,y=2; सार्वजनिक: int sum() स्थिरांक {वापसी x + y;} शून्य स्केल (int f) {x * = f; y*=f;}}; ए ए; ए.स्केल(3); अदालत
A
9 9
B
3 3
C
6 6
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=1*3=3, y=2*3=6. sum()=3+6=9. Output: 9.
व्याख्या (हिन्दी) x=1*3=3, y=2*3=6. योग()=3+6=9. आउटपुट: 9.
29
EN + हिं
GB What is 'module' in C++20 related to encapsulation?
IN C++20 में एनकैप्सुलेशन से संबंधित 'मॉड्यूल' क्या है?
A
Replaces header files; exports only declared interface हेडर फ़ाइलों को प्रतिस्थापित करता है; केवल घोषित इंटरफ़ेस निर्यात करता है
B
Like namespaces नामस्थान की तरह
C
Dynamic loading गतिशील लोडिंग
D
Separate compilation units अलग संकलन इकाइयाँ
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) C++20 modules improve encapsulation by explicitly controlling what is exported from a compilation unit.
व्याख्या (हिन्दी) C++20 मॉड्यूल एक संकलन इकाई से निर्यात की जाने वाली चीज़ों को स्पष्ट रूप से नियंत्रित करके इनकैप्सुलेशन में सुधार करते हैं।
30
EN + हिं
GB What is the output: class A{int x; public: void setX(int v){x=v;} int getX()const{return x;}}; A a; cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: void setX(int v){x=v;} int getX()const{return x;}}; ए ए; अदालत
B
Undefined behavior अपरिभाषित व्यवहार
C
Compile error संकलन त्रुटि
D
Garbage कचरा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x is uninitialized; reading it is undefined behavior (no in-class initializer, no constructor initialization). Output: UB.
व्याख्या (हिन्दी) x अप्रारंभीकृत है; इसे पढ़ना अपरिभाषित व्यवहार है (कोई इन-क्लास इनिशियलाइज़र नहीं, कोई कंस्ट्रक्टर इनिशियलाइज़ेशन नहीं)। आउटपुट: यूबी.
16–30 of 107