Test Series - oops

Test Number 54/78

Q: If virtual functions are defined in the base class then _______________
A. It is not necessary for derived classes to override those functions
B. It is necessary for derived classes to override those functions
C. Those functions can never be derived
D. Those functions must be overridden by all the derived classes
Solution: The derived classes doesn’t have to redefine and override the base class functions. If one definition is already given it is not mandatory for any derived class to override those functions. The base class definition will be used.
Q: Non-const functions _______________________
A. Can be called only from non-const object
B. Can be called only from const object
C. Can be called both by const and non-const object
D. Can’t be called with object
Solution: The non-const functions are able to modify the values of object which called the function. So only the non-const functions can be called. If const object is used then the compiler produces an error as the const object is being given to a function which can modify its values.
Q: Which is the correct condition on const member functions?
A. Const member functions can’t call non-const member functions
B. Const member functions can’t call any other function
C. Const member functions can call only the functions which are neither const nor non-const
D. Const member functions can call only data members of call not member functions
Solution: The const member functions are restricted to call any other non-const member functions. This is to ensure that the const function doesn’t have any code that might modify the calling object.
Q: Which keyword must be used to declare a member function as a constant member function?
A. Constant
B. Const
C. FunctionConst
D. Unchanged
Solution: The keyword const is provided in most of the programming languages. This indicates that the member on which it is specified remains constant with the respective values of members. The keyword must be mentioned so as to declare a member function to be constant.
Q: 
A. 
B. 
C. 
D. 
Solution: 
Q: If a const object calls a non-const member function then ____________________
A. Run time error may get produced
B. Compile time error may get produced
C. Either compile time or run time error is produced
D. The program can’t be compiled
Solution: The program gets compiled but produces an error. The error is produced because a constant value is being changed. Even if there is no code that can change any object value, but non-const member functions are assumed to change the values.
Q: Which is the correct condition on const member functions?
A. Const member functions can’t call non-const member functions
B. Const member functions can’t call any other function
C. Const member functions can call only the functions which are neither const nor non-const
D. Const member functions can call only data members of call not member functions
Solution: The const member functions are restricted to call any other non-const member functions. This is to ensure that the const function doesn’t have any code that might modify the calling object.
Q: If a const object calls a non-const member function then ____________________
A. Run time error may get produced
B. Compile time error may get produced
C. Either compile time or run time error is produced
D. The program can’t be compiled
Solution: The program gets compiled but produces an error. The error is produced because a constant value is being changed. Even if there is no code that can change any object value, but non-const member functions are assumed to change the values.
Q: Non-const functions _______________________
A. Can be called only from non-const object
B. Can be called only from const object
C. Can be called both by const and non-const object
D. Can’t be called with object
Solution: The non-const functions are able to modify the values of object which called the function. So only the non-const functions can be called. If const object is used then the compiler produces an error as the const object is being given to a function which can modify its values.
Q: Which objects can call the const functions?
A. Only const objects
B. Only non-const objects
C. Both const and non-const objects
D. Neither const not non-const objects
Solution: All the objects of a class can call const functions for its use. Const objects can call the const functions to since those values are already constant. And the non- const objects can call the const functions to keep their values constant.
Q: Which feature of OOP is exhibited by the function overriding?
A. Inheritance
B. Abstraction
C. Polymorphism
D. Encapsulation
Solution: The polymorphism feature is exhibited by function overriding. Polymorphism is the feature which basically defines that same named functions can have more than one functionalities.
Q: Abstract functions of a base class _________________
A. Are overridden by the definition in same class
B. Are overridden by the definition in parent class
C. Are not overridden generally
D. Are overridden by the definition in derived class
Solution: The functions declared to be abstract in base class are redefined in derived classes. That is, the functions are overridden by the definitions given in the derived classes. This must be done to give at least one definition to each undefined function.
Q: In Kotlin, the function to be overridden must be ______________
A. Private
B. Open
C. Closed
D. Abstract
Solution: The function to be overridden must be open. This is a condition in Kotlin for any function to be overridden. This avoids accidental overriding.
Q: What are the constant member functions?
A. Functions which doesn’t change value of calling object
B. Functions which doesn’t change value of any object inside definition
C. Functions which doesn’t allow modification of any object of class
D. Functions which doesn’t allow modification of argument objects
Solution: The constant member functions are a special type of member functions. These are intended to restrict any modification in to the values of object which is used to invoke that function. This is done to ensure that there are no accidental modifications to the object.

You Have Score    /14