Question

1.
2.
3.
4.
Answer (Detailed Solution Below)

Option 4 : BA

Advertisement

Detailed Solution

सही उत्तर BA है।

Key Points
Helpful?
PrepSnapprepsnap.in • Part -A

Question:

What is the output of the following C++ program? class A { public: virtual ~A() { cout << "A"; } }; class B : public A { public: ~B() { cout << "B"; } }; int main() { A *p = new B(); delete p; } / निम्नलिखित C++ प्रोग्राम का आउटपुट क्या है?

1.
A
2.
B
3.
AB
4.
BA

Correct Answer: BA

Because the destructor is virtual, delete through a base pointer first runs the derived destructor ("B") and then the base destructor ("A"), printing "BA". / चूँकि डिस्ट्रक्टर virtual है, बेस पॉइंटर से delete करने पर पहले व्युत्पन्न डिस्ट्रक्टर ("B") फिर बेस डिस्ट्रक्टर ("A") चलता है, अतः "BA" प्रिंट होता है।

Downloaded from PrepSnap (prepsnap.in)