Home / C++ Programming / Constructors and Destructors :: Programs

C++ Programming :: Constructors and Destructors

  1. What will be the output of the following program?

    
     #include
      class GateBase
      {      
          public:  
          GateBase()   
          {       
             cout"Base OK. ";   
          }     
          ~GateBase()    
          {          
             cout"Base DEL. ";     
          }
      }; 
      class GateDerived: public BixBase
      {  
         public:   
         GateDerived()    
      {     
        cout"Derived OK. ";  
      }   
      ~GateDerived()   
       {       
         cout"Derived DEL. ";    
       }
     };
     int main()
     { 
        GateBase *basePtr = new GateDerived();     
        delete basePtr; 
        return 0;
     }
    

  2. A.

    Base OK. Derived OK.

    B.

    Base OK. Derived OK. Base DEL.

    C.

    Base OK. Derived OK. Derived DEL.

    D.

    Base OK. Derived OK. Derived DEL. Base DEL.

    E.

    Base OK. Derived OK. Base DEL. Derived DEL.

    View Answer

    Workspace

    Discuss Discuss in Forum


  3. What will be the output of the following program?

     #include
      class GateBase 
      {    
          public:   
          GateBase()     
          {      
             cout"Base OK. ";     
          }  
          virtual ~GateBase()   
          {      
             cout"Base DEL. ";    
          }
       };
       class GateDerived: public BixBase 
       {     
           public:  
           GateDerived()    
       {        
           cout"Derived OK. ";  
       }   
        ~GateDerived()    
       {      
           cout"Derived DEL. ";   
        }  
     }; 
     int main() 
     {    
          GatetBase *basePtr = new GateDerived();     
          delete basePtr; 
          return 0; 
    }
    

  4. A.

    Base OK. Derived OK.

    B.

    Base OK. Derived OK. Base DEL.

    C.

    Base OK. Derived OK. Derived DEL.

    D.

    Base OK. Derived OK. Derived DEL. Base DEL.

    E.

    Base OK. Derived OK. Base DEL. Derived DEL.

    View Answer

    Workspace

    Discuss Discuss in Forum


  5. What will be the output of the following program?

     #include
      class GateBase
      {
         public:  
         int x, y;    
         GateBase(int xx = 0, int yy = 5)    
         {         
             x = ++xx;     
             y = --yy;   
         }
         void Display()     
         {       
              cout class GateDerived : public GateBase
          {    
          public:  
          void Increment()   
          {       
               y++;    
          }     
          void Display()    
          {         
              cout
       }:  }
       int main() 
       {    
             GateDerived objGate;     
             objGate.Increment();     
             objGate.Display();  
             return 0;  
       }
    

  6. A.

    3

    B.

    4

    C.

    5

    D.

    Garbage-value

    E.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  7. Which of the following statement is correct about the program given below?

      #include
       class FresherGate 
       {   
            int x;  
            public:      
                FresherGate()      
                {          
                   x = 0;      
                }         
                FresherGate(int xx)        
                {        
                    x = xx;       
                }         
                FresherGate(FresherGate &objB)      
                {     
                   x = objB.x;   
                }     
                void Display()   
                {       
                    cout" ";   
                }
      };
      int main()
      {    
           FresherGate objA(25);  
           FresherGate objB(objA);    
           FresherGate objC = objA;      
           objA.Display(); 
           objB.Display();  
           objC.Display();  
           return 0;  
    }
    

  8. A.

    The program will print the output 25 25 25 .

    B.

    The program will print the output 25 Garbage 25 .

    C.

    The program will print the output Garbage 25 25 .

    D.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  9. Which of the following statement is correct about the program given below?

      #include 
      class FresherGate
      {   
            int x, y;     
            public:     
              FresherGate()      
              {            
                 x = 0;         
                 y = 0;        
              }         
              FresherGate(int xx, int yy)     
              {           
                  x = xx;       
                  y = yy;         
             }
             FresherGate(FresherGate *objB)  
             {        
                 x = objB->x;        
                 y = objB->y;     
            }     
            void Display()   
            {        
              cout" "  int main() 
      {  
         FresherGate  objGate( new FresherGate(20, 40) );     
         objGate.Display(); 
         return 0; 
      }
    

  10. A.

    The program will print the output 0 0 .

    B.

    The program will print the output 20 40 .

    C.

    The program will print the output Garbage Garbage .

    D.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  11. What will be the out of the following program?

     #include 
      class GateBase
      {    
          public:   
          int x, y;    
          public:   
          GateBase(int xx = 0, int yy = 0)        
          {     
              x = xx;     
              y = yy;  
          }  
      }; 
      class GateDerived : public GateBase 
      {   
           private:    
             GateBase objBase;  
          public:    
          GateDerived(int xx, int yy) : GateBase(xx), objBase(yy)     
           {      
              cout this->x   " "               
                   this->y   " "   
                   " "    
                   " ";  
         }   
        ~GateDerived()  
         { } 
     };
     int main() 
     {    
          GateDerived objDev(11, 22);  
          return 0;
     }
    

     

  12. A.

    11 22 0 0

    B.

    11 0 0 22

    C.

    11 0 22 0

    D.

    11 22 11 22

    E.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum


  13. What will be the out of the following program?

    #include 
     class GateBase
     {    
         public:   
         int x, y;    
         public:     
         GateBase(int xx = 0, int yy = 0)    
         {         
              x = xx;        
              y = yy;     
          }
        };
        class GateDerived : public GateBase 
        {    
           private:     
               GateBase objBase;   
          public:   
          GateDerived(int xx, int yy) : GateBase(xx), objBase(yy)    
         {
             cout " "   
                  this->x    " "         
                  " "                   
                  this->objBase.x ; 
         }  
        ~GateDerived()  
         { } 
     };
      int main() 
      {    
          GateDerived objDev(11, 22);    
          return 0;
      }
    

  14. A.

    11 22 0 0

    B.

    11 11 0 22

    C.

    11 11 11 0

    D.

    11 11 11 22

    E.

    The program will report compile time error.

    View Answer

    Workspace

    Discuss Discuss in Forum