Test Series - oops

Test Number 53/78

Q: Which among the following best describes member function overriding?
A. Member functions having same name in base and derived classes
B. Member functions having same name in base class only
C. Member functions having same name in derived class only
D. Member functions having same name and different signature inside main function
Solution: The member function which is defined in base class and again in the derived class, is overridden by the definition given in the derived class. This is because the preference is given more to the local members. When derived class object calls that function, definition from the derived class is used.
Q: The functions to be overridden _____________
A. Must be private in base class
B. Must not be private base class
C. Must be private in both derived and base class
D. Must not be private in both derived and base class
Solution: If the function is private in the base class, derived class won’t be able to access it. When the derived class can’t access the function to be overridden then it won’t be able to override it with any definition.
Q: Which is the correct condition for function overriding?
A. The declaration must not be same in base and derived class
B. The declaration must be exactly the same in base and derived class
C. The declaration should have at least 1 same argument in declaration of base and derived class
D. The declaration should have at least 1 different argument in declaration of base and derived class
Solution: For a function to be over ridden, the declaration must be exactly the same. There must not be any different syntax used. This will ensure that the function to be overridden is only the one intended from to be overridden from the derived class.
Q: Exactly same declaration in base and derived class includes______________
A. Only same name
B. Only same return type and name
C. Only same return type and argument list
D. All the same return type, name and parameter list
Solution: Declaration includes the whole prototype of the function. The return type name and the parameter list must be same in order to confirm that the function is same in derived and the base class. And hence can be overridden.
Q: How to access the overridden method of base class from the derived class?
A. Using arrow operator
B. Using dot operator
C. Using scope resolution operator
D. Can’t be accessed once overridden
Solution: Scope resolution operator :: can be used to access the base class method even if overridden. To access those, first base class name should be written followed by the scope resolution operator and then the method name.
Q: Which among the following is true?
A. Inheritance must not be using when overriding is used
B. Overriding can be implemented without using inheritance
C. Inheritance must be done, to use overriding are overridden
D. Inheritance is mandatory only if more than one functions
Solution: The inheritance must be used in order to use function overriding. If inheritance is not used, the functions can only be overloaded. There must be a base class and a derived class to override the function of base class.
Q: What should be used to call the base class method from the derived class if function overriding is used in Java?
A. Keyword super
B. Scope resolution
C. Dot operator
D. Function name in parenthesis
Solution: The keyword super must be used to access base class members. Even when overriding is used, super must be used with the dot operator. The overriding is possible.
Q: In Delphi ______________
A. Method overriding is done implicitly
B. Method overriding is not supported
C. Method overriding is done with directive override
D. Method overriding is done with the directive virtually
Solution: This is possible but only if the method to be overridden is marked as dynamic or virtual. It is inbuilt restriction of programming language. This is done to reduce the accidental or unintentional overriding.
Q: In C# ____________________
A. Non – virtual or static methods can’t be overridden
B. Non – virtual and static methods only can be overridden
C. Overriding is not allowed
D. Overriding must be implemented using C++ code only
Solution: The non-virtual and static methods can’t be overridden in C# language. The restriction is made from the language implicitly. Only the methods that are abstract, virtual or override can be overridden.
Q: Which language doesn’t support the method overriding implicitly?
A. C++
B. C#
C. Java
D. SmallTalk
Solution: The feature of method overriding is not provided in C#. To override the methods, one must use override or virtual keywords explicitly. This is done to remove accidental changes in program and unintentional overriding.

You Have Score    /10