Quiz: Classes & Objects

To View Tricks: Login Required

Number of Questions: 25

Question: 6 -

Which of the following can be overloaded?

Options:
  1. Operators

  2. None of the above

  3. Object

  4. Both Object & Operators

  5. Answer:

    Both Object & Operators

    Solution:

    Object and Operators can be overloaded.


Question: 7 -

What happens when we try to compile the class definition in following code snippet?

class Birds {};
class Peacock : protected Birds {};

Options:
  1. It will not compile because a class cannot be protectedly inherited from other class.

  2. It will not compile because class body of Peacock is not defined.

  3. It will compile succesfully.

  4. It will not compile because class body of Birds is not defined.

  5. Answer:

    It will compile succesfully.

    Solution not available.

Question: 8 -

Which is also called as abstract class?

Options:
  1. Derived class

  2. Pure virtual function

  3. Virtual function

  4. None of the mentioned

  5. Answer:

    Pure virtual function

    Solution:

    Classes that contain at least one pure virtual function are called as abstract base classes.


Question: 9 -

Which of the following is true?

Options:
  1. Objects of a class do not share non-static members. Every object has its own copy

  2. All objects of a class share all data members of class

  3. None of these

  4. Objects of a class do not share codes of non-static methods, they have their own copy

  5. Answer:

    Objects of a class do not share non-static members. Every object has its own copy

    Solution:

    very object maintains a copy of non-static data members. For example, let Student be a class with data members as name, year, batch. Every object of student will have its own name, year and batch. On a side note, static data members are shared among objects. All objects share codes of all methods


Question: 10 -

What will be the output of the following program?

         
Note:Includes all required header files
class course
{
    int x, y; 
    public:
    course(int xx)
    {
        x = ++xx;
    }
    void Display()
    {
        cout<< --x << " ";
    }
};
int main()
{
    course obj(20);
    obj.Display();
    int *p = (int*)&obj ;
    *p = 5;
    obj.Display();
    return 0; 
}

Options:
  1. 21 4

  2. 20 4

  3. 21 5

  4. 20 5

  5. Answer:

    20 4

    Solution not available.