Test Series - oops

Test Number 50/78

Q: Member functions _____________________
A. Must be defined inside class body
B. Can be defined inside class body or outside
C. Must be defined outside the class body
D. Can be defined in another class
Solution: The functions definitions can be given inside or outside the body of class. If defined inside, general syntax is used. If defined outside then the class name followed by scope resolution operator and then function name must be given for the definition.
Q: Which among the following is true?
A. Member functions can never be private
B. Member functions can never be protected
C. Member functions can never be public
D. Member functions can be defined in any access specifier
Solution: The member functions can be defined inside any specifier. There is no restriction. The programmer can apply restrictions on its use by specifying the access specifier with the functions.
Q: Which keyword is used to define the static member functions?
A. static
B. stop
C. open
D. state
Solution: The static keyword is used to declare any static member function in a class. The static members become common to each object of the class being created. They share the same values.
Q: Which keyword is used to define the inline member function?
A. no keyword required
B. inline
C. inlined
D. line
Solution: The inline keyword is used to defined the inline member functions in a class. The functions are implicitly made inline if defined inside the class body, but only if they doesn’t have any complex statement inside. All functions defined outside the class body must be mentioned with an explicit inline keyword.
Q: Which among the following are valid ways of overloading the operators?
A. Only using friend function
B. Only using member function
C. Either member functions or friend functions can be used
D. Operators can’t be overloaded
Solution: The operators can be overloaded by using the member function or even the friend functions can be used. This is because both of these can access all the data members of a class.
Q: Which among the following is mandatory condition for operators overloading?
A. Overloaded operator must be member function of the left operand
B. Overloaded operator must be member function of the right operand
C. Overloaded operator must be member function of either left or right operand
D. Overloaded operator must not be dependent on the operands
Solution: The operator to be overloaded must be made the member function of the operand on left side of expressions to be used. This allows the compiler to identify whether the overloading has to be used or not. This rule also reduces the ambiguity in code.
Q: When the operator to be overloaded becomes the left operand member then ______________
A. The right operand acts as implicit object represented by *this
B. The left operand acts as implicit object represented by *this
C. Either right or left operand acts as implicit object represented by *this
D. *this pointer is not applicable in that member function
Solution: The left operand becomes the object that is referred by *this pointer in the member function that will be called while using operator overloading. This is done to point to a specific object on which the overloading will be applied.
Q: If the left operand is pointed by *this pointer, what happens to other operands?
A. Other operands are passed as function return type
B. Other operands are passed to compiler implicitly
C. Other operands must be passed using another member function
D. Other operands are passed as function arguments
Solution: The operands that are used during overloading expect the left operand, can be passed as function arguments. Those are then referred in function definition with the names specified in the argument list.
Q: If a friend overloaded operator have to be changed to member overloaded operator, which operator should be used with the class name?
A. Scope resolution operator
B. Colon
C. Arrow operator
D. Dot operator
Solution: The scope resolution operator can be used followed by the class name. Then the operator keyword with the operator symbol that should be overloaded. This is done to use member function instead of friend function.
Q: What is the syntax to overload an operator?
A. className::operator(parameters)
B. className:operator(parameters)
C. className.operator(paramteres)
D. className->operator(parameters)
Solution: The class name is followed by the scope resolution operator. This is done to specify the class to which the function should belong to. Then the keyword operator should be used in order to indicate the operator that is to be overloaded. Then come the parameters list to specify other operands.

You Have Score    /10