256
GB
What is the output of destructor order for: class A{public:~A(){cout<<'A';}}; class B{A a; public:~B(){cout<<'B';}}; B b;
IN
डिस्ट्रक्टर ऑर्डर का आउटपुट क्या है: क्लास ए{पब्लिक:~ए(){काउट
A
AB
अब
B
BA
बी ० ए
C
A
ए
D
B
बी
✅ Correct Answer:
💡 Explanation / व्याख्या
Explanation (English)
B's destructor body runs first (prints B), then member a's destructor runs (prints A). Wait — destructor body of B runs first then member destructors. Output: BA. Correcting: B::~B body runs (cout<<'B'), then A::~A runs (cout<<'A'). Output: BA.
व्याख्या (हिन्दी)
बी का डिस्ट्रक्टर बॉडी पहले चलता है (बी को प्रिंट करता है), फिर सदस्य ए का डिस्ट्रक्टर चलता है (ए को प्रिंट करता है)। रुको - बी का विध्वंसक निकाय पहले चलता है फिर सदस्य विध्वंसक। आउटपुट: बी.ए. सुधार: बी::~बी बॉडी रन (काउट)।