Test Series - oops

Test Number 7/78

Q: Which among the following best describes polymorphism?
A. It is the ability for a message/data to be processed in more than one form
B. It is the ability for a message/data to be processed in only 1 form
C. It is the ability for many messages/data to be processed in one way
D. It is the ability for undefined message/data to be processed in at least one way
Solution: It is actually the ability for a message / data to be processed in more than one form. The word polymorphism indicates many-forms. So if a single entity takes more than one form, it is known as polymorphism.
Q: What do you call the languages that support classes but not polymorphism?
A. Class based language
B. Procedure Oriented language
C. Object-based language
D. If classes are supported, polymorphism will always be supported
Solution: The languages which support classes but doesn’t support polymorphism, are known as object-based languages. Polymorphism is such an important feature, that is a language doesn’t support this feature, it can’t be called as a OOP language.
Q: Which among the following is the language which supports classes but not polymorphism?
A. SmallTalk
B. Java
C. C++
D. Ada
Solution: Ada is the language which supports the concept of classes but doesn’t support the polymorphism feature. It is an object-based programming language. Note that it’s not an OOP language.
Q: If same message is passed to objects of several different classes and all of those can respond in a different way, what is this feature called?
A. Inheritance
B. Overloading
C. Polymorphism
D. Overriding
Solution: The feature defined in question defines polymorphism features. Here the different objects are capable of responding to the same message in different ways, hence polymorphism.
Q: Which type of function among the following shows polymorphism?
A. Inline function
B. Virtual function
C. Undefined functions
D. Class member functions
Solution: Only virtual functions among these can show polymorphism. Class member functions can show polymorphism too but we should be sure that the same function is being overloaded or is a function of abstract class or something like this, since we are not sure about all these, we can’t say whether it can show polymorphism or not.
Q: In case of using abstract class or function overloading, which function is supposed to be called first?
A. Local function
B. Function with highest priority in compiler
C. Global function
D. Function with lowest priority because it might have been halted since long time, because of low priority
Solution: Function with highest priority is called. Here, it’s not about the thread scheduling in CPU, but it focuses on whether the function in local scope is present or not, or if scope resolution is used in some way, or if the function matches the argument signature. So all these things define which function has the highest priority to be called in runtime. Local function could be one of the answer but we can’t say if someone have used pointer to another function or same function name.
Q: Which among the following can’t be used for polymorphism?
A. Static member functions
B. Member functions overloading
C. Predefined operator overloading
D. Constructor overloading
Solution: Static member functions are not property of any object. Hence it can’t be considered for overloading/overriding. For polymorphism, function must be property of object, not only of class.
Q: Which among the following can show polymorphism?
A. Overloading ||
B. Overloading +=
C. Overloading <<
D. Overloading &&
Solution: Only insertion operator can be overloaded among all the given options. And the polymorphism can be illustrated here only if any of these is applicable of being overloaded. Overloading is type of polymorphism.
Q: Which problem may arise if we use abstract class functions for polymorphism?
A. All classes are converted as abstract class
B. Derived class must be of abstract type
C. All the derived classes must implement the undefined functions
D. Derived classes can’t redefine the function
Solution: The undefined functions must be defined is a problem, because one may need to implement few undefined functions from abstract class, but he will have to define each of the functions declared in abstract class. Being useless task, it is a problem sometimes.
Q: If 2 classes derive one base class and redefine a function of base class, also overload some operators inside class body. Among these two things of function and operator overloading, where is polymorphism used?
A. Function overloading only
B. Operator overloading only
C. Both of these are using polymorphism
D. Either function overloading or operator overloading because polymorphism can be applied only once in a program
Solution: Both of them are using polymorphism. It is not necessary that polymorphism can be used only once in a program, it can be used anywhere, any number of times in a single program.

You Have Score    /10