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
361
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.
362
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.
व्याख्या (हिन्दी) इंटरफ़ेस पृथक्करण (आईएसपी) का मतलब है कि ग्राहकों को उन इंटरफेस पर निर्भर नहीं रहना चाहिए जिनका वे उपयोग नहीं करते हैं - यह अच्छी तरह से इनकैप्सुलेटेड डिज़ाइन से संबंधित है।
363
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.
364
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.
365
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.
व्याख्या (हिन्दी) किसी वर्ग के अंदर एक मित्र वर्ग की घोषणा उस मित्र वर्ग के सभी तरीकों को निजी/संरक्षित सदस्यों तक पहुंच प्रदान करती है।
366
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.
व्याख्या (हिन्दी) मित्र संचालिका
367
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.
व्याख्या (हिन्दी) निजी कंस्ट्रक्टर सिंगलटन जैसे पैटर्न लागू करते हैं, जहां ऑब्जेक्ट निर्माण को फ़ैक्टरी विधि के माध्यम से नियंत्रित किया जाता है।
368
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.
369
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 मॉड्यूल एक संकलन इकाई से निर्यात की जाने वाली चीज़ों को स्पष्ट रूप से नियंत्रित करके इनकैप्सुलेशन में सुधार करते हैं।
370
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 अप्रारंभीकृत है; इसे पढ़ना अपरिभाषित व्यवहार है (कोई इन-क्लास इनिशियलाइज़र नहीं, कोई कंस्ट्रक्टर इनिशियलाइज़ेशन नहीं)। आउटपुट: यूबी.
371
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.
व्याख्या (हिन्दी) उच्च सामंजस्य का मतलब है कि एक वर्ग की एक स्पष्ट, अच्छी तरह से परिभाषित जिम्मेदारी है - एक अच्छी एनकैप्सुलेशन गुणवत्ता।
372
EN + हिं
GB What is abstraction in C++?
IN C++ में अमूर्तन क्या है?
A
Showing essential features, hiding unnecessary details आवश्यक विशेषताएँ दिखाना, अनावश्यक विवरण छिपाना
B
Making all members private सभी सदस्यों को निजी बनाना
C
Using templates टेम्प्लेट का उपयोग करना
D
Runtime polymorphism रनटाइम बहुरूपता
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Abstraction is presenting the necessary interface while hiding the underlying complexity from the user.
व्याख्या (हिन्दी) एब्स्ट्रैक्शन उपयोगकर्ता से अंतर्निहित जटिलता को छिपाते हुए आवश्यक इंटरफ़ेस प्रस्तुत कर रहा है।
373
EN + हिं
GB What is the output: class Shape{public: virtual double area()=0;}; class Circle:public Shape{double r; public: Circle(double r):r(r){} double area(){return 3.14*r*r;}}; Shape*s=new Circle(1); printf("%.2f",s->area());
IN आउटपुट क्या है: क्लास शेप{पब्लिक: वर्चुअल डबल एरिया()=0;}; वर्ग वृत्त:सार्वजनिक आकार{डबल आर; सार्वजनिक: सर्कल(डबल आर):आर(आर){} डबल एरिया(){रिटर्न 3.14*आर*आर;}}; आकार*s=नया वृत्त(1); printf("%2f",s->क्षेत्र());
A
3.14 3.14
B
1.00 1.00
C
0.00 0.00
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Circle::area()=3.14*1*1=3.14. Output: 3.14.
व्याख्या (हिन्दी) वृत्त::क्षेत्र()=3.14*1*1=3.14. आउटपुट: 3.14.
374
EN + हिं
GB What is an 'interface' in C++ abstraction?
IN C++ एब्स्ट्रैक्शन में 'इंटरफ़ेस' क्या है?
A
Abstract class with only pure virtual functions and no data केवल शुद्ध आभासी कार्यों वाला सार वर्ग और कोई डेटा नहीं
B
A template class एक टेम्पलेट क्लास
C
A header file एक हेडर फ़ाइल
D
A namespace एक नामस्थान
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Interfaces in C++ are modeled as abstract classes with only pure virtual functions — they define a contract.
व्याख्या (हिन्दी) C++ में इंटरफेस को केवल शुद्ध वर्चुअल फ़ंक्शंस के साथ अमूर्त वर्गों के रूप में तैयार किया गया है - वे एक अनुबंध को परिभाषित करते हैं।
375
EN + हिं
GB What is the output: class A{public: virtual int f()=0; virtual ~A()=default;}; class B:public A{public: int f(){return 42;}}; A*p=new B; cout<f();
IN What is the output: class A{public: virtual int f()=0; आभासी ~ए()=डिफ़ॉल्ट;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: int f() {वापसी 42;}}; ए*पी=नया बी; अदालत
A
42 42
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B implements f()=42. p->f() via virtual dispatch returns 42. Output: 42.
व्याख्या (हिन्दी) बी f()=42 लागू करता है। वर्चुअल डिस्पैच रिटर्न के माध्यम से p->f() 42। आउटपुट: 42।
361–375 of 1915