Question: 6 -
Which of the following can be overloaded?
-
Operators
-
None of the above
-
Object
-
Both Object & Operators
Answer:
Both Object & Operators
Solution:
Object and Operators can be overloaded.
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 {};
-
It will not compile because a class cannot be protectedly inherited from other class.
-
It will not compile because class body of Peacock is not defined.
-
It will compile succesfully.
-
It will not compile because class body of Birds is not defined.
Answer:
It will compile succesfully.
Solution not available.
Question: 8 -
Which is also called as abstract class?
-
Derived class
-
Pure virtual function
-
Virtual function
-
None of the mentioned
Answer:
Pure virtual function
Solution:
Classes that contain at least one pure virtual function are called as abstract base classes.
Classes that contain at least one pure virtual function are called as abstract base classes.
Question: 9 -
Which of the following is true?
-
Objects of a class do not share non-static members. Every object has its own copy
-
All objects of a class share all data members of class
-
None of these
-
Objects of a class do not share codes of non-static methods, they have their own copy
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
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;
}
-
21 4
-
20 4
-
21 5
-
20 5
Answer:
20 4