250+ TOP MCQs on Overriding Member Functions and Answers

Object Oriented Programming Interview Questions freshers on “Overriding Member Functions”.

1. 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
Answer: a
Clarification: 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.

2. 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
Answer: c
Clarification: 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.

3. 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
Answer: b
Clarification: 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.

4. 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
Answer: d
Clarification: 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.

5. Which among function will be overridden from the function defined in derived class below:

class A
{
	int i;
	void show()
	{ 
		cout<<i; 
	}
	void print()
	{ 
		cout <<i; 
	}
};
class B
{
	int j;
	void show()
	{ 
		cout<<j; 
	}
};

a) show()
b) print()
c) show() and print()
d) Compile time error
Answer: a
Clarification: The declaration must be exactly same in the derived class and base class. The derived class have defined show() function with exactly same declaration. This then shows that the function in base class is being overridden if show() is called from the object of class B.

6. 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
Answer: c
Clarification: 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.

7. 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
Answer: b
Clarification: 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.

8. Which language doesn’t support the method overriding implicitly?
a) C++
b) C#
c) Java
d) SmallTalk
Answer: b
Clarification: 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.

9. 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
Answer: a
Clarification: 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.

10. 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
Answer: c
Clarification: 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.

11. 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
Answer: a
Clarification: 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.

12. In Kotlin, the function to be overridden must be ______________
a) Private
b) Open
c) Closed
d) Abstract
Answer: b
Clarification: The function to be overridden must be open. This is a condition in Kotlin for any function to be overridden. This avoids accidental overriding.

13. 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
Answer: d
Clarification: 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.

14. 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
Answer: a
Clarification: 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.

15. Which feature of OOP is exhibited by the function overriding?
a) Inheritance
b) Abstraction
c) Polymorphism
d) Encapsulation
Answer: c
Clarification: 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.

Object Oriented Programming for Interviews,

Leave a Reply

Your email address will not be published. Required fields are marked *