Question
1.
2.
3.
4.
Answer (Detailed Solution Below)
Option 3 : 1234
Advertisement
Detailed Solution
सही उत्तर 1234 है।
Key Points
Helpful?
Question:
Consider the C++ fragment: class A { public: A(){cout<<"1";} ~A(){cout<<"4";} }; class B : public A { public: B(){cout<<"2";} ~B(){cout<<"3";} }; int main(){ B obj; } What is printed? / C++ कोड खंड पर विचार करें: class A { public: A(){cout<<"1";} ~A(){cout<<"4";} }; class B : public A { public: B(){cout<<"2";} ~B(){cout<<"3";} }; int main(){ B obj; } क्या मुद्रित होगा?
1.
2143
2.
1324
3.
1234
4.
2413
Correct Answer: 1234
The base constructor runs before the derived constructor (1 then 2); destruction is the reverse, derived first then base (3 then 4), giving 1234. / आधार कंस्ट्रक्टर व्युत्पन्न कंस्ट्रक्टर से पहले चलता है (पहले 1 फिर 2); विनाश उल्टा होता है, पहले व्युत्पन्न फिर आधार (पहले 3 फिर 4), अतः 1234।
Downloaded from PrepSnap (prepsnap.in)