1. Question: Which of the following statements are true for operator overloading in C++?

    A
    Operators can be overloaded globally

    B
    Operators can be overloaded locally

    C
    Operators can not be overloaded globally

    D
    none

    Note: Not available
    1. Report
  2. Question: Consider the following code:
    #include<stdio.h>
    int main(int argc, char* argv[])
    {
            enum Colors 
            {
                    red,
                    blue,
                    white = 5,
                    yellow,
                    green,
                    pink
            };
            Colors color = green;
            printf("%d", color);
            return 0;
    }
    What will be the output when the above code is compiled and executed?

    A
    7

    B
    8

    C
    9

    D
    10

    Note: Not available
    1. Report
  3. Question: What will happen when the following code is compiled and executed?
    #include<iostream>
    using namespace std;
    class myclass
    {
    private:
        int number;
    public:
        myclass()
        {
            number = 2;
        }
        int &a()
        {
            return number;
        }
    };
    
    int main() 
    {
        myclass m1,m2;
        m1.a() = 5; 
        m2.a() = m1.a();
        cout << m2.a();
        return 0;
    }

    A
    Compile Error

    B
    The printed output will be 5

    C
    The printed output will be 0

    D
    The printed output will be 7

    Note: Not available
    1. Report
  4. Question: Consider the sample code given below and answer the question that follows.
    class A
    {
    public:
    A() {}
    ~A()
    {
    cout << "in destructor" << endl;
    }
    };
    void main()
    {
    A a;
    a.~A();
    }
    How many times will "in destructor" be output when the above code is compiled and executed?

    A
    1

    B
    2

    C
    3

    D
    4

    Note: Not available
    1. Report
  5. Question: Consider the following code:
    class BaseException
    {
       public:
       virtual void Output()
       {
          cout << "Base Exception" << endl;
       }
    };
    class DerivedException : public BaseException
    {
       public:
       virtual void Output()
       {
          cout << "Derived Exception" << endl;
       }
    };
    void ExceptionTest()
    {
       try
       {
          throw new DerivedException();
       }
       catch (DerivedException ex)
       {
          ex.Output();
       }
       catch (...)
       {
          cout << "Unknown Exception Thrown!" << endl;
       }
    }
    Invoking Exception Test will result in which output?

    A
    Derived Exception

    B
    Unknown Exception

    C
    BaseException

    D
    Error

    Note: Not available
    1. Report
  6. Question: Consider the sample code given below and answer the question that follows.
    class Shape
    {
    public:
    virtual void draw() = 0;
    };
    class Rectangle: public Shape
    {
    public:
    void draw()
    {
    // Code to draw rectangle
    }
    //Some more member functions.....
    };
    class Circle : public Shape
    {
    public:
    void draw()
    {
    // Code to draw circle
    }
    //Some more member functions.....
    };
    int main()
    {
    Shape objShape;
    objShape.draw();
    }
    What happens if the above program is compiled and executed?

    A
    Compile error

    B
    Exception error

    C
    0

    D
    None

    Note: Not available
    1. Report
  7. Question: What will be the output of the following code?
    class A
    {
    public:
          A():pData(0){}
          ~A(){}
          int operator ++()
          {
                pData++;
                cout << "In first ";
                return pData;
          }
          int operator ++(int)
          {
                pData++;
                cout << "In second ";
                return pData;
          }
    private:
          int pData;
    };
    
    void main()
    {
         A a;
         cout << a++;
         cout << ++a;
    }

    A
    In second 1 in first 2

    B
    In first 2 in first 1

    C
    In first 1 in first 2

    D
    In second 1 in first 1

    Note: Not available
    1. Report
  8. Question: Consider the following code:
    #define SQ(a) (a*a)
    int  answer = SQ(2 + 3);
    What will be the value of answer after the above code executes?

    A
    10

    B
    11

    C
    12

    D
    13

    Note: Not available
    1. Report
  9. Question: Which of the following operators cannot be overloaded?

    A
    +=

    B
    >>

    C
    <

    D
    .

    E
    ::

    F
    &&

    G
    =

    H
    ?:

    Note: Not available
    1. Report
  10. Question: Which of the following statements are FALSE with regard to destructors

    A
    A derived class can call the destructor of the parent class explicitly

    B
    A class may have only one destructor

    C
    Destructors cannot be invoked directly

    D
    The return type for a destructor is void

    E
    Destructors cannot accept arguments

    Note: Not available
    1. Report
Copyright © 2024. Powered by Intellect Software Ltd