logo

CuriousTab

CuriousTab

Discussion


Home C++ Programming Objects and Classes See What Others Are Saying!
  • Question
  • What happens when we try to compile the class definition in following code snippet?
    class Birds {};
    class Peacock : protected Birds {};


  • Options
  • A. It will not compile because class body of Birds is not defined.
  • B. It will not compile because class body of Peacock is not defined.
  • C. It will not compile because a class cannot be protectedly inherited from other class.
  • D. It will compile succesfully.

  • Correct Answer
  • It will compile succesfully. 


  • More questions

    • 1. What is correct about the following program?
      #include<iostream.h> 
      class Addition
      {
          int x; 
          public: 
          Addition()
          {
              x = 0;
          }       
          Addition(int xx)
          {
              x = xx;
          }
          Addition operator + (int xx = 0)
          {
              Addition objTemp; 
              objTemp.x = x + xx; 
              return(objTemp);
          }
          void Display(void)
          {
              cout<< x << endl;
          }
      };
      int main()
      {
          Addition objA(15), objB;
          objB = objA + 5;
          objB.Display();
          return 0; 
      }

    • Options
    • A. The program will print the output 20.
    • B. The program will report run time error.
    • C. The program will print the garbage value.
    • D. Compilation fails due to 'operator +' cannot have default arguments.
    • Discuss
    • 2. Which of the following statement is correct about the program given below?
      #include<iostream.h> 
      class CuriousTabBase
      {
          int x, y; 
          public:
          CuriousTabBase(int xx = 10, int yy = 10)
          {
              x = xx;
              y = yy;
          }
          void Show()
          {
              cout<< x * y << endl;
          }
      };
      class CuriousTabDerived
      {
          private:
              CuriousTabBase objBase; 
          public:
          CuriousTabDerived(int xx, int yy) : objBase(xx, yy)
          {
              objBase.Show();
          }
      };
      int main()
      {
          CuriousTabDerived objDev(10, 20);
          return 0; 
      }

    • Options
    • A. The program will print the output 100.
    • B. The program will print the output 200.
    • C. The program will print the output Garbage-value.
    • D. The program will report compile time error.
    • Discuss
    • 3. What will be the output of the following program?
      #include<iostream.h> 
      class Point
      {
          int x, y; 
          public:
          Point(int xx = 10, int yy = 20)
          {
              x = xx;
              y = yy; 
          }
          Point operator + (Point objPoint)
          {
              Point objTmp;
              objTmp.x = objPoint.x + this->x; 
              objTmp.y = objPoint.y + this->y;
              return objTmp;
          }
          void Display(void)
          {
              cout<< x << " " << y;
          }
      };
      int main()
      {
          Point objP1;
          Point objP2(1, 2);
          Point objP3 = objP1 + objP2;
          objP3.Display(); 
          return 0; 
      }

    • Options
    • A. 1 2
    • B. 10 20
    • C. 11 22
    • D. Garbage Garbage
    • E. The program will report compile time error.
    • Discuss
    • 4. Which of the following statement is correct about the program given below?
      #include<iostream.h>
      #include<string.h> 
      class CuriousTab
      {
          public:
          void GetData(char *s, int x, int y )
          {
              int i = 0;
              for (i = x-1; y>0; i++)
              {
                  cout<< s[i];
                  y--; 
              } 
          }
      }; 
      int main()
      {
          CuriousTab objCuriousTab;
          objCuriousTab.GetData((char*)"Welcome!", 1, 3);
          return 0; 
      }

    • Options
    • A. The program will print the output me!.
    • B. The program will print the output Wel.
    • C. The program will print the output !em.
    • D. The program will print the output Welcome!.
    • E. The program will result in a compile time error.
    • Discuss
    • 5. Which of the following statement is correct about the program given below?
      #include<iostream.h> 
      int i, j; 
      class CuriousTab
      {
          public:
          CuriousTab(int x = 0, int y = 0)
          {
              i = x; 
              j = x; 
              Display();
          }
          void Display()
          {
              cout<< j <<" ";
          } 
      }; 
      int main()
      {
          CuriousTab objCuriousTab(10, 20); 
          int &s = i; 
          int &z = j; 
          i++;
          cout<< s-- << " " << ++z; 
          return 0; 
      }

    • Options
    • A. The program will print the output 0 11 21.
    • B. The program will print the output 10 11 11.
    • C. The program will print the output 10 11 21.
    • D. The program will print the output 10 11 12.
    • E. It will result in a compile time error.
    • Discuss
    • 6. What will be the output of the following program?
      #include<iostream.h> 
      class Base
      {
          public:
          int S, A, M; 
          Base(int x, int y)
          {
              S = y - y;
              A = x + x; 
              M = x * x;
          }
          Base(int, int y = 'A', int z = 'B')
          {
              S = y;
              A = y + 1 - 1; 
              M = z - 1;
          }
          void Display(void)
          {
              cout<< S << " " << A << " " << M << endl;
          }
      };
      class Derived : public Base
      {
          int x, y, z; 
          public:
          Derived(int xx = 65, int yy = 66, int zz = 67): Base(x)
          {
              x = xx; 
              y = yy;
              z = zz;
          }
          void Display(int n)
          {
              if(n)
                  Base::Display(); 
              else
                  cout<< x << " " << y << " " << z << endl; 
          }
      };
      int main()
      {
          Derived objDev; 
          objDev.Display(-1); 
          return 0;
      }

    • Options
    • A. 65 65 65
    • B. 65 66 67
    • C. A A A
    • D. A B C
    • E. The program will report compile time error.
    • Discuss
    • 7. What will be the output of the following program?
      #include<iostream.h>
      int CuriousTabFunction(int a, int b = 3, int c = 3)
      {
          cout<< ++a * ++b * --c ; 
          return 0;
      }
      int main()
      {
          CuriousTabFunction(5, 0, 0); 
          return 0;
      }

    • Options
    • A. 8
    • B. 6
    • C. -6
    • D. -8
    • Discuss
    • 8. Which of the following statement is correct?

    • Options
    • A. Two functions having same number of argument, order and type of argument can be overloaded if both functions do not have any default argument.
    • B. Overloaded function must have default arguments.
    • C. Overloaded function must have default arguments starting from the left of argument list.
    • D. A function can be overloaded more than once.
    • Discuss
    • 9. What does a class hierarchy depict?

    • Options
    • A. It shows the relationships between the classes in the form of an organization chart.
    • B. It describes "has a" relationships.
    • C. It describes "kind of" relationships.
    • D. It shows the same relationship as a family tree.
    • Discuss
    • 10. Which of the following statement is correct about the program given below?
      #include<iostream.h> 
      class CuriousTab
      {
          int x; 
          float y; 
          public:
          void Function()
          {
              x = 4; 
              y = 2.50; delete this;
          }
          void Display()
          {
              cout<< x << " " << y;
          } 
      }; 
      int main()
      {
          CuriousTab *pCuriousTab = new CuriousTab();
          pCuriousTab->Function(); 
          pCuriousTab->Function(); 
          pCuriousTab->Display(); 
          return 0; 
      }

    • Options
    • A. The program will print the output 4 2.5.
    • B. The program will print the output 4.
    • C. The program will report runtime error.
    • D. The program will report compile time error.
    • Discuss


    Comments

    There are no comments.

Enter a new Comment