class Test
{
public:
Test()
{
cout<<"constructor invoked"<<endl;
}
~Test()
{
cout<<"Destructor invoked"<<endl;
}
};
Test t1;
void main(void)
{
cout<<"main begins";
Test t2;
{
cout<<"Block begins" <<endl;
Test t3;
cout<<"block Ends"<<endl;
}
cout<<"main ends"<<endl;
}
Output:
constructor invoked//for t1
main begins
constructor invoked//for t2
block begins
constructor invoked//for t3
block ends
Destructor invoked//for t3
main ends
Destructor invoked//for t2
Destructor invoked//for t1
{
public:
Test()
{
cout<<"constructor invoked"<<endl;
}
~Test()
{
cout<<"Destructor invoked"<<endl;
}
};
Test t1;
void main(void)
{
cout<<"main begins";
Test t2;
{
cout<<"Block begins" <<endl;
Test t3;
cout<<"block Ends"<<endl;
}
cout<<"main ends"<<endl;
}
Output:
constructor invoked//for t1
main begins
constructor invoked//for t2
block begins
constructor invoked//for t3
block ends
Destructor invoked//for t3
main ends
Destructor invoked//for t2
Destructor invoked//for t1




No comments:
Post a Comment