OOP Using C++ — MCQ Practice

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

📚 101 Questions 🌐 Hindi + English ✅ Free
भाषा / Language:
101 questions
1
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.
व्याख्या (हिन्दी) एब्स्ट्रैक्शन उपयोगकर्ता से अंतर्निहित जटिलता को छिपाते हुए आवश्यक इंटरफ़ेस प्रस्तुत कर रहा है।
2
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.
3
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++ में इंटरफेस को केवल शुद्ध वर्चुअल फ़ंक्शंस के साथ अमूर्त वर्गों के रूप में तैयार किया गया है - वे एक अनुबंध को परिभाषित करते हैं।
4
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।
5
EN + हिं
GB What is 'type erasure' in C++?
IN C++ में 'टाइप इरेज़र' क्या है?
A
Hiding concrete type behind abstract interface अमूर्त इंटरफ़ेस के पीछे ठोस प्रकार छिपाना
B
Removing type information at compile time संकलन समय पर प्रकार की जानकारी हटाना
C
Template specialization टेम्पलेट विशेषज्ञता
D
Dynamic casting गतिशील कास्टिंग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Type erasure (e.g., std::function, std::any) stores objects of different types behind a uniform interface.
व्याख्या (हिन्दी) टाइप इरेज़र (उदाहरण के लिए, std::function, std::any) एक समान इंटरफ़ेस के पीछे विभिन्न प्रकार की वस्तुओं को संग्रहीत करता है।
6
EN + हिं
GB What is the output: class A{protected: int x; public: A(int v):x(v){} virtual void show()=0;}; class B:public A{public: B(int v):A(v){} void show(){cout<
IN आउटपुट क्या है: क्लास ए {संरक्षित: int x; सार्वजनिक: A(int v):x(v){} वर्चुअल शून्य शो()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: बी (int v): ए (v) {} शून्य शो() {cout
A
7 7
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B constructor passes v to A, setting x=7. show() outputs x=7. Output: 7.
व्याख्या (हिन्दी) B कंस्ट्रक्टर v को A से पास करता है, x=7 सेट करता है। दिखाएँ() आउटपुट x=7। आउटपुट: 7.
7
EN + हिं
GB What is 'concept' in C++20?
IN C++20 में 'अवधारणा' क्या है?
A
Named set of requirements on template arguments टेम्पलेट तर्कों पर आवश्यकताओं का नामित सेट
B
A runtime type check एक रनटाइम प्रकार की जाँच
C
A new keyword for abstract class अमूर्त वर्ग के लिए एक नया कीवर्ड
D
An interface definition एक इंटरफ़ेस परिभाषा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Concepts (C++20) allow expressing semantic constraints on template parameters: template.
व्याख्या (हिन्दी) अवधारणाएँ (C++20) टेम्प्लेट मापदंडों पर अर्थ संबंधी बाधाओं को व्यक्त करने की अनुमति देती हैं: टेम्प्लेट।
8
EN + हिं
GB What is the output: class Animal{public: virtual string sound()=0; string describe(){return "I say: "+sound();}}; class Dog:public Animal{public: string sound(){return "Woof";}}; Dog d; cout<
IN आउटपुट क्या है: क्लास एनिमल{पब्लिक: वर्चुअल स्ट्रिंग साउंड()=0; स्ट्रिंग वर्णन(){वापसी "मैं कहता हूं: "+ध्वनि();}}; वर्ग कुत्ता:सार्वजनिक पशु{सार्वजनिक: स्ट्रिंग ध्वनि(){वापसी "वूफ़";}}; कुत्ता घ; अदालत
A
I say: Woof मैं कहता हूं: वूफ़
B
Woof वाह
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) describe() calls virtual sound() which dispatches to Dog::sound()=Woof. Output: I say: Woof.
व्याख्या (हिन्दी) डिस्क्रिप्शन() वर्चुअल साउंड() को कॉल करता है जो डॉग::साउंड()=वूफ को भेजता है। आउटपुट: मैं कहता हूं: वूफ।
9
EN + हिं
GB What is 'dependency inversion principle'?
IN 'निर्भरता व्युत्क्रम सिद्धांत' क्या है?
A
Depend on abstractions, not on concrete types अमूर्त पर निर्भर रहें, ठोस प्रकारों पर नहीं
B
Inverting class hierarchy वर्ग पदानुक्रम को उलटना
C
Using virtual destructors वर्चुअल डिस्ट्रक्टर्स का उपयोग करना
D
Dependency injection container निर्भरता इंजेक्शन कंटेनर
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) DIP (D in SOLID): high-level modules should not depend on low-level modules; both should depend on abstractions.
व्याख्या (हिन्दी) डीआईपी (एसओएलआईडी में डी): उच्च-स्तरीय मॉड्यूल को निम्न-स्तरीय मॉड्यूल पर निर्भर नहीं होना चाहिए; दोनों को अमूर्तन पर निर्भर रहना चाहिए।
10
EN + हिं
GB What is the output: template T maxVal(T a,T b){return a>b?a:b;} cout<
IN आउटपुट क्या है: टेम्पलेट T maxVal(T a,T b){return a>b?a:b;} cout
A
72.5 72.5
B
73 73
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) maxVal(3,7)=7, maxVal(2.5,1.5)=2.5. Output: 72.5.
व्याख्या (हिन्दी) मैक्सवैल(3,7)=7, मैक्सवैल(2.5,1.5)=2.5। आउटपुट: 72.5.
11
EN + हिं
GB What is the output: class Stack{vector v; public: void push(int x){v.push_back(x);} int pop(){int x=v.back();v.pop_back();return x;}}; Stack s; s.push(1); s.push(2); cout<
IN आउटपुट क्या है: क्लास स्टैक{वेक्टर v; सार्वजनिक: शून्य पुश(int x){v.push_back(x);} int पॉप(){int x=v.back();v.pop_back();रिटर्न x;}}; ढेर एस; एस.पुश(1); एस.पुश(2); अदालत
A
2 2
B
1 1
C
Undefined अपरिभाषित
D
Compile error संकलन त्रुटि
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) LIFO: push 1, push 2. pop() returns last=2. Output: 2.
व्याख्या (हिन्दी) LIFO: पुश 1, पुश 2. पॉप() अंतिम = 2 लौटाता है। आउटपुट: 2.
12
EN + हिं
GB What is 'generic programming'?
IN 'जेनेरिक प्रोग्रामिंग' क्या है?
A
Writing code independent of specific types using templates टेम्प्लेट का उपयोग करके विशिष्ट प्रकारों से स्वतंत्र कोड लिखना
B
Runtime type checking रनटाइम प्रकार की जाँच
C
Virtual function usage आभासी फ़ंक्शन का उपयोग
D
Procedural programming प्रक्रियात्मक प्रोग्रामिंग
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Generic programming (templates in C++) writes algorithms/data structures that work with any type satisfying requirements.
व्याख्या (हिन्दी) जेनेरिक प्रोग्रामिंग (C++ में टेम्प्लेट) एल्गोरिदम/डेटा संरचनाएं लिखता है जो किसी भी प्रकार की संतोषजनक आवश्यकताओं के साथ काम करता है।
13
EN + हिं
GB What is 'template specialization' as abstraction?
IN अमूर्तन के रूप में 'टेम्पलेट विशेषज्ञता' क्या है?
A
Providing specific implementation for particular type विशेष प्रकार के लिए विशिष्ट कार्यान्वयन प्रदान करना
B
Specializing pure virtual functions शुद्ध आभासी कार्यों में विशेषज्ञता
C
Runtime type selection रनटाइम प्रकार चयन
D
Namespace specialization नेमस्पेस विशेषज्ञता
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Template specialization allows customizing behavior for specific types while sharing generic interface.
व्याख्या (हिन्दी) टेम्प्लेट विशेषज्ञता सामान्य इंटरफ़ेस साझा करते समय विशिष्ट प्रकारों के लिए व्यवहार को अनुकूलित करने की अनुमति देती है।
14
EN + हिं
GB What is the output: auto square=[](auto x){return x*x;}; cout<
IN आउटपुट क्या है: ऑटो वर्ग=[](ऑटो x){रिटर्न x*x;}; अदालत
A
96.25 96.25
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
3 6.25 3 6.25
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) square(3)=9, square(2.5)=6.25. Output: 96.25.
व्याख्या (हिन्दी) वर्ग(3)=9, वर्ग(2.5)=6.25. आउटपुट: 96.25.
15
EN + हिं
GB What is 'std::function' and type erasure?
IN 'std::function' और प्रकार मिटाना क्या है?
A
Wraps any callable with matching signature, hiding concrete type ठोस प्रकार को छुपाते हुए, मिलान करने योग्य हस्ताक्षर के साथ किसी भी कॉल करने योग्य को लपेटता है
B
A function pointer एक फ़ंक्शन सूचक
C
A virtual function एक आभासी कार्य
D
A lambda only केवल एक लैम्ब्डा
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) std::function can hold lambdas, function pointers, or functors — erasing concrete type.
व्याख्या (हिन्दी) std::फ़ंक्शन लैम्ब्डा, फ़ंक्शन पॉइंटर्स, या फ़ैक्टर्स को पकड़ सकता है - कंक्रीट प्रकार को मिटा सकता है।
1–15 of 101