Test Series - oops

Test Number 46/78

Q: If object of lowest level class is created (last derived class) ________________ of its parent class constructors are called.
A. Few
B. All
C. Only parent and parent
D. Base and Derived
Solution: When derived class object is created, all of its successor parent classes constructors are called. Constructor of all the connected classes is not created. Since the parent members have to be initialised, but other derived classes are not needed.
Q: If hybrid inheritance is used, it mostly shows _______________ feature of OOP.
A. Flexibility
B. Reusability
C. Efficiency
D. Code readability
Solution: The code is reusable in most of the classes and the data becomes more linked to other classes. Other features are also exhibited, but the code reusability is used the most. Code readability becomes relatively less. Flexibility increases but it depends on how the hybrid inheritance is used.
Q: The sequence of destructors being called while using hybrid inheritance is ____________
A. Reverse of constructors being called
B. Reverse of classes being made
C. Reverse of objects being created
D. Reverse of code calling objects
Solution: The destructors are always called in reverse order of constructors being called always. The type of inheritance doesn’t matter. The only important concept is the sequence of classes being inherited.
Q: Virtual function is ______ class function which expected to be redefined in ______ class, so that when reference is made to derived class object using pointer then we can call virtual function to execute ________ class definition version.
A. Base, derived, derived
B. Derived, Derived, Derived
C. Base, derived, base
D. Base, base, derived
Solution: The functions which may give rise to ambiguity due to inheritance, can be declared virtual. So that whenever derived class object is referred using pointer or reference to the base class methods, we can still call the derived class methods using virtual function. Hence this differentiates those methods from each other.
Q: What does a virtual function ensure for an object, among the following?
A. Correct method is called, regardless of the class defining it
B. Correct method is called, regardless of the object being called
C. Correct method is called, regardless of the type of reference used for function call
D. Correct method is called, regardless of the type of function being called by objects
Solution: It is property of the virtual function and one of their main use. Its use ensure that the correct method is called even though it is been called from different pointer or references. This also decreases chance of mistakes in program.
Q: Virtual functions are mainly used to achieve _____________
A. Compile time polymorphism
B. Interpreter polymorphism
C. Runtime polymorphism
D. Functions code polymorphism
Solution: It is used to achieve runtime polymorphism. The functions which are inherited and overridden, so at runtime the correct function is executed. The correct function call is made from the intended class.
Q: Which keyword is used to declare virtual functions?
A. virtual
B. virt
C. anonymous
D. virtually
Solution: The virtual keyword is used to declare virtual functions. Anonymous keyword is used with classes and have a different meaning. The virtual functions are used to call the intended function of the derived class.
Q: Where the virtual function should be defined?
A. Twice in base class
B. Derived class
C. Base class and derived class
D. Base class
Solution: The virtual function should be declared in base class. So that when the derived class inherits from the base class, the functions can be differentiated from the one in base class and another in derived class.
Q: The resolving of virtual functions is done at ______________
A. Compile time
B. Interpret time
C. Runtime
D. Writing source code
Solution: The resolving of virtual functions that are to be called is done at run time. The base class and the derived classes may contain different definitions and different variables, so all these things are resolved at run time and decided which function is to be called.
Q: In which access specifier should a virtual function be defined?
A. Private
B. Public
C. Protected
D. Default
Solution: The virtual functions must be defined in public section of a class. This is to ensure that the virtual function is available everywhere in the program. Also to avoid any error while resolving the method.

You Have Score    /10