logo

CuriousTab

CuriousTab

Discussion


Home C++ Programming Objects and Classes See What Others Are Saying!
  • Question
  • 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.

  • Correct Answer
  • 11 22 


  • More questions

    • 1. How many instances of an abstract class can be created?

    • Options
    • A. 1
    • B. 5
    • C. 13
    • D. 0
    • Discuss
    • 2. Which of the following keywords is used to control access to a class member?

    • Options
    • A. Default
    • B. Break
    • C. Protected
    • D. Asm
    • Discuss
    • 3. Which of the following also known as an instance of a class?

    • Options
    • A. Friend Functions
    • B. Object
    • C. Member Functions
    • D. Member Variables
    • Discuss
    • 4. Which of the following factors supports the statement that reusability is a desirable feature of a language?

    • Options
    • A. It decreases the testing time.
    • B. It lowers the maintenance cost.
    • C. It reduces the compilation time.
    • D. Both A and B.
    • Discuss
    • 5. How many times a constructor is called in the life-time of an object?

    • Options
    • A. Only once
    • B. Twice
    • C. Thrice
    • D. Depends on the way of creation of object
    • Discuss
    • 6. What will be the output of the following program?
      #include<iostream.h> 
      int main()
      {
          float Amount;
          float Calculate(float P = 5.0, int N = 2, float R = 2.0);
          Amount = Calculate(); 
          cout<< Amount << endl; 
          return 0;
      }
      
      float Calculate(float P, int N, float R)
      {
          int Year = 1;
          float Sum = 1 ;
          Sum = Sum * (1 + P * ++N * R);
          Year =  (int)(Year + Sum);
          return Year; 
      }

    • Options
    • A. 21
    • B. 22
    • C. 31
    • D. 32
    • E. None of these
    • Discuss
    • 7. Which of the following is an abstract data type?

    • Options
    • A. int
    • B. double
    • C. string
    • D. Class
    • Discuss
    • 8. Can a class have virtual destructor?

    • Options
    • A. Yes
    • B. No
    • Discuss
    • 9. Which of the following statement is correct?

    • Options
    • A. A referenced has to be de-referenced to access a value.
    • B. A referenced does not need to be de-referenced to access a value.
    • C. A referenced has to be double de-referenced to access a value.
    • D. Whether a reference should be de-referenced or not depends on the type of the reference.
    • Discuss
    • 10. Which of the following cannot be declared as virtual?

    • Options
    • A. Constructor
    • B. Destructor
    • C. Data Members
    • D. Both A and C
    • Discuss


    Comments

    There are no comments.

Enter a new Comment