Aptitude (12) ASP.NET (2) Automata (4) Browser (1) C (5) C# (1) C++ (10) Code (3) CSS (1) Data Structure (1) DATABASE (3) HTML (1) java (43) JSP (1) math (1) MySql (8) other (6) php (3) Servlet (3)

Saturday, 9 March 2013

Scope of an object

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


No comments:

Post a Comment