Chapter V: Classes and Objects
1. The declaration of a class includes
a) Declaration of data members
b) Declaration of function prototype
c) Return statements of functions
d) Both a and b
2. By default, the members of a class are
a) private
b) public
c) protected
d) static
3. Which OOP feature can be enabled by using private declaration for the class members?
a) Data abstraction
b) Polymorphism
c) Encapsulation
d) Modularity
4. Which of the following will assign the value to the class member variable num?
void getnum(int a)
a) {num=a};
b) {num=a;}
c) {a=num};
d) {a=num;}
5. Which of the following is not true about member functions?
a) Can access private data variables
b) Can call another function directly without using dot operator
c) Both a and b
d) None of the above
6. Identify all the members of the following class xyz:
class xyz
{
int x,y;
public:
xyz();
void calc(int a, int b);
void output_calc(void);
};
a) Data members x and y
b) Data members x and y, Constructor, and member functions calc() and
output_calc()
c) Data members x and y, and member functions calc() and output_calc()
d) Constructor and member functions calc() and output_calc()
7. Which of the following is not true about static member variable?
a) Only one instance of static member can be created
b) Visible only within the class
c) It can be initialized whenever necessary
d) Both a and b
8. What is the general format of calling a static member function using a class name?
a) class-name :: function-name
b) function-name :: class-name
c) class-name :: function-name;
d) function-name :: class-name;
9. Which of the following is true while passing objects as function arguments? It is possible
a) to pass copy of the entire object to the function
b) to pass only the address of the object to the function
c) to pass the objects to a non-member function
d) All of the above
10. A friend function
I. Can be invoked similar to other functions without using objects
II. Cannot access to other member functions directly
III. Cannot be called using the object of the class to which it has been
declared as friend
IV. Can be declared only in the public part of a class
a) I, II and III
b) I, II and IV
c) I, II, III and IV
d) IV only