Multiple choice technology programming languages

class A { A{cout<<"I am a constructor of A";} ~A{cout<<"I am a destructor of A";} } class B { A{cout<<"I am a constructor of B";} ~A{cout<<"I am a destructor of B";} }int main() { A a1; B b1; return 0; }

  1. I am a constructor of A,I am a destructor of A,I am a constructor of B,I am a destructor of B

  2. I am a constructor of A,I am a constructor of B,I am a destructor of A,I am a destructor of B

  3. I am a constructor of A,I am a constructor of B,I am a destructor of B,I am a destructor of A

  4. I am a destructor of B,I am a constructor of A,I am a destructor of A,I am a constructor of B

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

When objects are created on the stack, constructors execute in order of declaration (a1 first, then b1). When main() returns, destructors execute in reverse order (b1's destructor first, then a1's), following the LIFO (Last In, First Out) principle of stack unwinding.