logo

CuriousTab

CuriousTab

Discussion


Home C++ Programming Constructors and Destructors See What Others Are Saying!
  • Question
  • What will be the output of the following program?
    #include<iostream.h> 
    class CuriousTabBase
    {
        public:
        int x, y;
        CuriousTabBase(int xx = 0, int yy = 5)
        {
            x = ++xx; 
            y = --yy;
        }
        void Display()
        {
            cout<< --y;
        } 
        ~CuriousTabBase(){} 
    };
    class CuriousTabDerived : public CuriousTabBase
    {
        public:
        void Increment()
        {
            y++;
        }
        void Display()
        {
            cout<< --y;
        } 
    }; 
    int main()
    {
        CuriousTabDerived objCuriousTab;
        objCuriousTab.Increment();
        objCuriousTab.Display();
        return 0; 
    }


  • Options
  • A. 3
  • B. 4
  • C. 5
  • D. Garbage-value
  • E. The program will report compile time error.

  • Correct Answer



  • More questions

    • 1. What happens if the base and derived class contains definition of a function with same prototype?

    • Options
    • A. Compiler reports an error on compilation.
    • B. Only base class function will get called irrespective of object.
    • C. Only derived class function will get called irrespective of object.
    • D. Base class object will call base class function and derived class object will call derived class function.
    • Discuss
    • 2. When are the Global objects destroyed?

    • Options
    • A. When the control comes out of the block in which they are being used.
    • B. When the program terminates.
    • C. When the control comes out of the function in which they are being used.
    • D. As soon as local objects die.
    • Discuss
    • 3. Which of the following is correct about the statements given below?

      1. All operators can be overloaded in C++.
      2. We can change the basic meaning of an operator in C++.

    • Options
    • A. Only I is true.
    • B. Both I and II are false.
    • C. Only II is true.
    • D. Both I and II are true.
    • Discuss
    • 4. Which of the following statement is correct about the program given below?
      #include<iostream.h> 
      class CuriousTab
      {
          int x; 
          public:
              CuriousTab()
              {
                 x = 0;
              }
              CuriousTab(int xx)
              {
                  x = xx; 
              }
              CuriousTab(CuriousTab &objB)
              {
                  x = objB.x; 
              }
              void Display()
              {
                  cout<< x << " ";
              }
      };
      int main()
      {
          CuriousTab objA(25);
          CuriousTab objB(objA);
          CuriousTab objC = objA;
          objA.Display();
          objB.Display();
          objC.Display();
          return 0; 
      }

    • Options
    • 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.
    • Discuss
    • 5. In which of the following a virtual call is resolved at the time of compilation?

    • Options
    • A. From inside the destructor.
    • B. From inside the constructor.
    • C. From inside the main().
    • D. Both A and B.
    • Discuss
    • 6. Which of the following statement is correct?

    • Options
    • A. Overloaded functions can have at most one default argument.
    • B. An overloaded function cannot have default argument.
    • C. All arguments of an overloaded function can be default.
    • D. A function if overloaded more than once cannot have default argument.
    • Discuss
    • 7. What will be the output of the following program?
      #include<iostream.h> 
      class Base
      {
          int x, y; 
          public:
          Base() 
          {
              x = y = 0; 
          } 
          Base(int xx)
          {
              x = xx;
          }
          Base(int p, int q = 10)
          {
              x = p + q;
              y = q; 
          } 
          void Display(void)
          {
              cout<< x << " " << y << endl;
          } 
      }objDefault(1, 1);
      
      class Derived: public Base
      {
          Base obj; 
          public:
          Derived(int xx, int yy): Base(xx, xx + 1)
          { }
          Derived(Base objB = objDefault)
          { } 
      }; 
      int main()
      {
          Derived objD(5, 3);
          Derived *ptrD = new Derived(objD);
          ptrD->Display();
          delete ptrD;
          return 0; 
      }

    • Options
    • A. 3 2
    • B. 8 3
    • C. 11 6
    • D. 11 10
    • E. The program will not compile successfully.
    • Discuss
    • 8. Which of the following statements is correct?

      1. We can return a global variable by reference.
      2. We cannot return a local variable by reference.

    • Options
    • A. Only 1 is correct.
    • B. Only 2 is correct.
    • C. Both 1 and 2 are correct.
    • D. Both 1 and 2 are incorrect.
    • Discuss
    • 9. Which of the following constructor is used in the program given below?
      #include<iostream.h> 
      class CuriousTab
      {
          int x, y; 
          public:
          CuriousTab(int xx = 10, int yy = 20 )
          {
              x = xx; 
              y = yy;
          }
          void Display()
          {
              cout<< x << " " << y << endl;
          } 
          ~CuriousTab()
          { } 
      };
      int main()
      {
          CuriousTab objCuriousTab; 
          objCuriousTab.Display(); 
          return 0;
      }

    • Options
    • A. Copy constructor
    • B. Simple constructor
    • C. Non-parameterized constructor
    • D. Default constructor
    • Discuss
    • 10. What will be the output of the following program?
      #include<iostream.h> 
      class CuriousTabBase
      {
          public:
              float x; 
      }; 
      class CuriousTabDerived : public CuriousTabBase
      {
          public: 
              char ch; 
              void Process()
              {
                  ch = (int)((x=12.0)/3.0);
              }
              void Display()
              {
                  cout<< (int)ch;
              } 
      }; 
      int main()
      {
          class CuriousTabDerived  *objDev = new CuriousTabDerived;
          objDev->Process();
          objDev->Display();
          return 0; 
      }

    • Options
    • A. The program will print the output 4.
    • B. The program will print the ASCII value of 4.
    • C. The program will print the output 0.
    • D. The program will print the output garbage.
    • Discuss


    Comments

    There are no comments.

Enter a new Comment