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
946
EN + हिं
GB What is 'class invariant enforcement'?
IN 'वर्ग अपरिवर्तनीय प्रवर्तन' क्या है?
A
Setter validates input to maintain invariant सेटर अपरिवर्तनीय बनाए रखने के लिए इनपुट को मान्य करता है
B
Constructor only केवल कंस्ट्रक्टर
C
Runtime assertion रनटाइम दावा
D
Exception only केवल अपवाद
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Invariant: balance>=0. Setter: if(v<0) throw; ensures invariant holds for all valid operations.
व्याख्या (हिन्दी) अपरिवर्तनीय: संतुलन>=0. सेटर: यदि(v
947
EN + हिं
GB What is the output: class A{int x=0; public: A& operator<<(int v){x+=v;return *this;} int get()const{return x;}}; A a; a<<1<<2<<3; cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: ए एवं ऑपरेटर
A
6 6
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=0+1+2+3=6. Output: 6.
व्याख्या (हिन्दी) x=0+1+2+3=6. आउटपुट: 6.
948
EN + हिं
GB What is the output: class A{int x=0; public: int get()const{return x;} void set(int v){x=(v>0?v:x);}}; A a; a.set(-1); a.set(5); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: int get()const{return x;} void set(int v){x=(v>0?v:x);}}; ए ए; ए.सेट(-1); ए.सेट(5); अदालत
A
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) -1 rejected; 5 accepted. x=5. Output: 5.
व्याख्या (हिन्दी) -1 अस्वीकृत; 5 स्वीकृत. एक्स=5. आउटपुट: 5.
949
EN + हिं
GB What is the output: class A{int x; public: A(int v):x(v){} operator string()const{return to_string(x);}}; A a(42); string s=a; cout<
IN आउटपुट क्या है: class A{int x; सार्वजनिक: A(int v):x(v){} ऑपरेटर स्ट्रिंग()const{return to_string(x);}}; ए ए(42); स्ट्रिंग एस=ए; अदालत
A
42 42
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) operator string() returns "42". s="42". Output: 42.
व्याख्या (हिन्दी) ऑपरेटर स्ट्रिंग() "42" लौटाता है। एस='42' आउटपुट: 42.
950
EN + हिं
GB What is the output: class A{vector v; public: void add(int x){v.push_back(x);} int size()const{return v.size();} int at(int i)const{return v.at(i);}}; A a; a.add(1);a.add(2);a.add(3); cout<
IN आउटपुट क्या है: क्लास ए {वेक्टर वी; सार्वजनिक: void add(int x){v.push_back(x);} int size()const{return v.size();} int at(int i)const{return v.at(i);}}; ए ए; a.जोड़ें(1);a.जोड़ें(2);a.जोड़ें(3); अदालत
A
32 32
B
23 23
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) size=3, at(1)=2. Output: 32.
व्याख्या (हिन्दी) आकार=3, पर(1)=2. आउटपुट: 32.
951
EN + हिं
GB What is the output: class A{int x=0; public: A& operator+=(int v){x+=v;return *this;} operator int()const{return x;}}; A a; a+=5; a+=3; cout<<(int)a;
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: A& ऑपरेटर+=(int v){x+=v;रिटर्न *यह;} ऑपरेटर int()const{रिटर्न x;}}; ए ए; ए+=5; ए+=3; अदालत
A
8 8
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) x=5+3=8. operator int()=8. Output: 8.
व्याख्या (हिन्दी) x=5+3=8. ऑपरेटर int()=8. आउटपुट: 8.
952
EN + हिं
GB What is the output: class A{int x=0; public: int get()const{return x;} friend A operator+(A a,const A& b){a.x+=b.x;return a;}}; A a; a.x; int y=0; //can't access x directly, use friend
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: int get()const{return x;} मित्र A ऑपरेटर+(A a,const A& b){a.x+=b.x;return a;}}; ए ए; a.x; int y=0; // सीधे x तक नहीं पहुंच सकता, मित्र का उपयोग करें
A
Compile error (can't set x from outside) संकलन त्रुटि (बाहर से x सेट नहीं किया जा सकता)
B
Works with friend दोस्त के साथ काम करता है
C
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Friend operator+ can access x. Output depends on usage.
व्याख्या (हिन्दी) मित्र ऑपरेटर+ x तक पहुंच सकता है। आउटपुट उपयोग पर निर्भर करता है।
953
EN + हिं
GB What is the output: class A{int x=0; public: void f(){x++;} int g()const{return x;}}; A *p=new A[3]; for(int i=0;i<3;i++) p[i].f(); cout<
IN आउटपुट क्या है: class A{int x=0; सार्वजनिक: void f(){x++;} int g()const{return x;}}; ए *पी=नया ए[3]; for(int i=0;i
A
1 1
B
3 3
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Each object gets its own x. p[1].f(): x=1. p[1].g()=1. Output: 1.
व्याख्या (हिन्दी) प्रत्येक वस्तु को अपना स्वयं का x मिलता है। पी[1].एफ(): x=1. पी[1].जी()=1. आउटपुट: 1.
954
EN + हिं
GB What is the output: class A{public:virtual int f()=0; int g(){return f()*2;}}; class B:public A{public:int f(){return 5;}}; B b; cout<
IN आउटपुट क्या है: class A{public:virtual int f()=0; int g(){रिटर्न f()*2;}}; कक्षा बी:सार्वजनिक ए{सार्वजनिक:int f(){वापसी 5;}}; बी बी; अदालत
A
10 10
B
5 5
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B::f()=5; g()=5*2=10. Output: 10.
व्याख्या (हिन्दी) बी::एफ()=5; जी()=5*2=10. आउटपुट: 10.
955
EN + हिं
GB What is the output: template T cube(T x){return x*x*x;} cout<
IN आउटपुट क्या है: टेम्पलेट टी क्यूब(टी एक्स){रिटर्न x*x*x;} कॉउट
A
278.0 278.0
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
27 8 27 8
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) cube(3)=27, cube(2.0)=8.0. Output: 278.
व्याख्या (हिन्दी) घन(3)=27, घन(2.0)=8.0. आउटपुट: 278.
956
EN + हिं
GB What is the output: class Stack{vectorv; public: void push(int x){v.push_back(x);} int top(){return v.back();} int size(){return v.size();}}; Stack s; s.push(1);s.push(2);s.push(3); cout<
IN आउटपुट क्या है: class Stack{vectorv; सार्वजनिक: शून्य पुश (int x) {v.push_back (x);} int टॉप() {रिटर्न v.back();} int आकार() {रिटर्न v.size();}}; ढेर एस; एस.पुश(1);एस.पुश(2);एस.पुश(3); अदालत
A
33 33
B
13 13
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) top=3, size=3. Output: 33.
व्याख्या (हिन्दी) शीर्ष=3, आकार=3. आउटपुट: 33.
957
EN + हिं
GB What is the output: class A{public:virtual void f()=0;}; class B:public A{public:void f()override{cout<<'B';}}; function fn=[]{B().f();}; fn();
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल वॉयड f()=0;}; कक्षा बी: सार्वजनिक ए {सार्वजनिक: शून्य एफ() ओवरराइड {काउट
A
B बी
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
Nothing कुछ नहीं
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) B().f()=B. Output: B.
व्याख्या (हिन्दी) बी().एफ()=बी. आउटपुट: बी.
958
EN + हिं
GB What is the output: auto add=[](int a,int b){return a+b;}; auto mul=[](int a,int b){return a*b;}; auto apply=[](auto f,int a,int b){return f(a,b);}; cout<
IN आउटपुट क्या है: auto add=[](int a,int b){return a+b;}; ऑटो mul=[](int a,int b){return a*b;}; स्वत: लागू=[](ऑटो एफ,इंट ए,इंट बी){रिटर्न एफ(ए,बी);}; अदालत
A
712 712
B
Compile error संकलन त्रुटि
C
Undefined अपरिभाषित
D
7 12 7 12
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) apply(add,3,4)=7; apply(mul,3,4)=12. Output: 712.
व्याख्या (हिन्दी) लागू करें(जोड़ें,3,4)=7; लागू करें(mul,3,4)=12। आउटपुट: 712.
959
EN + हिं
GB What is the output: class Queue{dequed; public: void enq(int x){d.push_back(x);} int deq(){int x=d.front();d.pop_front();return x;} int size(){return d.size();}}; Queue q; q.enq(1);q.enq(2);q.enq(3); cout<
IN आउटपुट क्या है: class Queue{dequed; सार्वजनिक: void enq(int x){d.push_back(x);} int deq(){int x=d.front();d.pop_front();return x;} int size(){return d.size();}}; कतार क्यू; q.enq(1);q.enq(2);q.enq(3); अदालत
A
12 12
B
32 32
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) deq()=1; remaining size=2. Output: 12.
व्याख्या (हिन्दी) डेक()=1; शेष आकार=2. आउटपुट: 12.
960
EN + हिं
GB What is the output: class A{public:virtual double compute(double x)=0;}; class Square:public A{public:double compute(double x)override{return x*x;}}; class Cube:public A{public:double compute(double x)override{return x*x*x;}}; vector ops={new Square,new Cube}; for(auto p:ops) cout<compute(3)<<' ';
IN आउटपुट क्या है: क्लास ए{पब्लिक:वर्चुअल डबल कंप्यूट(डबल x)=0;}; वर्ग वर्ग:सार्वजनिक ए{सार्वजनिक:डबल कंप्यूट(डबल एक्स)ओवरराइड{रिटर्न x*x;}}; क्लास क्यूब: सार्वजनिक ए {सार्वजनिक: डबल कंप्यूट (डबल एक्स) ओवरराइड {रिटर्न x*x*x;}}; वेक्टर ऑप्स = {नया वर्ग, नया घन}; for(ऑटो पी:ऑप्स) कॉउट
A
9 27 9 27
B
3 9 3 9
C
Compile error संकलन त्रुटि
D
Undefined अपरिभाषित
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English) Square(3)=9, Cube(3)=27. Output: 9 27.
व्याख्या (हिन्दी) वर्ग(3)=9, घन(3)=27. आउटपुट: 9 27.
946–960 of 1915