Machine-translated by Google. Questions are authored in English.
Top

Polymorphism and Virtual Functions Questions and Answers

Answer: C

If the base class destructor is not virtual, the destructor in the derived class cannot be called when the object is accessed through a pointer to the base class.

When delete is applied to a base class pointer that points to a derived object, the destructor is chosen by the pointer's static type unless it is virtual. Only the base class destructor runs, so the derived part is not cleaned up, which can leak resources (strictly, the behaviour is undefined).

A non-virtual base destructor can still be called and still has a body. It is the derived class destructor, not the base one, that is skipped, so options A, B and D are wrong.

Please log in or register to report this question.

2.

The pointer to base classes are commonly used in design of container classes such as set, vector and lists. In this case which of the following solution exists ?

(i) yields homogeneous list
(ii) yields heterogeneous list
(iii) special type of secure variation of heterogeneous list
(iv) homogeneous and heterogeneous list

Exam Year(s)

MH SET - 2021, SET Exam - 2021,

Answer: C

The key's answer is (i), (ii), (iii) and (iv). I could confirm the first three points in general but not the paper's source for the full list, so this follows the key.

A container of pointers to a base class can hold objects of any publicly derived class, because a base pointer may point at a derived object. Such a list is therefore heterogeneous (ii). If every element is created as the same class, the same container is homogeneous (i), so one design covers both (iv). The key also counts (iii), a secured variation of the heterogeneous list, which I could not match to a standard C++ term.

The options naming only one kind of list leave out something the same container can do.

Please log in or register to report this question.

3.

class C {
public:
  void f(int a) {cout \(\lt\lt\) a;}
  void f(int a, int b) {cout \(\lt\lt\) a+b;};
  void f(int a, int b, int c) {cout \(\lt\lt\) a+b+c;}
};
int main( )
{
  C obj;
  obj.f(10);
  obj.f(10, 20);
  obj.f(10, 20, 30);
  return 0;
}

The above C++ source code exemplifies which of the following principle with respect to object-oriented programming ?

Exam Year(s)

MH SET - 2024, SET Exam - 2024,

Answer: D

The code exemplifies polymorphism.

Class C defines three member functions with the same name f but different parameter lists. The compiler selects the right one from the arguments at each call, which is function overloading, a form of compile-time (static) polymorphism. The program prints 10, then 30, then 60.

Nothing here hides implementation details behind an interface (abstraction) or bundles data with access control as the point of the example (encapsulation), and there is no base or derived class, so it is not inheritance.

Please log in or register to report this question.

4.

Which of the following term describes the ability of a class to provide common interface for different types of objects in object-oriented programming ?

Exam Year(s)

MH SET - 2025, SET Exam - 2025,

Answer: B

The term is polymorphism.

Polymorphism lets objects of different classes be used through one common interface: a call such as shape.draw() runs the right version for a circle or a square. It is achieved through inheritance with overridden methods, interfaces and overloading.

Encapsulation hides an object's data behind its methods. Inheritance lets a class acquire the members of another; it supports polymorphism but is not the ability itself. Abstraction exposes essential features while hiding detail.

Please log in or register to report this question.

Answer: C

By default C++ provides early binding for variables and early binding for functions.

Variables are bound to their types and storage at compile time. Function calls, including calls to member functions, are also resolved at compile time unless the function is declared virtual; only then does C++ use late (dynamic) binding through the virtual table.

So late binding is something the programmer asks for with virtual, not the default. Every option with late binding for functions or variables describes non-default behaviour.

Please log in or register to report this question.

Answer: B

The true statement is that the parameter list must be different.

C++ chooses among overloaded functions by their signatures: the number, types and order of parameters. Two functions with the same name in the same scope must therefore differ in their parameter lists.

A difference in return type alone is not enough, because the compiler cannot tell from a call which version is wanted, so option A is wrong. Overloads normally live in the same class or scope, and constructors are among the most commonly overloaded functions (default, parameterised and copy constructors), so options C and D are false.

Please log in or register to report this question.

7.

Which concept allows different functions with the same name in C++ ?

Exam Year(s)

Tripura Public Service Commission - 2026,

Answer: B

The concept is function overloading.

Function overloading lets several functions share one name as long as their parameter lists differ in number or type, for example area(int) for a square and area(int, int) for a rectangle. The compiler picks the right one from the arguments at each call, which makes it a form of compile-time polymorphism.

Encapsulation bundles data with the functions that act on it. Inheritance lets a class derive members from another class. Data hiding restricts access to a class's internals with private and protected members. None of these allows two functions with the same name.

Please log in or register to report this question.

Answer: A

Polymorphism is the ability of an object to take many forms.

The word means 'many forms'. In OOP, one interface can be used with objects of different types, and the method that runs depends on the actual object, as when a base-class reference calls an overridden method in a subclass, or one method name is overloaded for different arguments.

Defining a method in a child class is overriding, one way polymorphism is achieved. Inheritance is a separate concept, and access to private data is governed by encapsulation.

Please log in or register to report this question.

9.

Which of the following is NOT an example of method overloading in Java ?

Exam Year(s)

Tripura Public Service Commission - 2025,

Answer: C

The case that is not overloading is Methods with different return types.

Java distinguishes overloaded methods by their parameter lists: different numbers or types of parameters. Two methods with the same name and parameters that differ only in return type cannot coexist; the compiler reports an error, because a call could not tell them apart.

Different numbers and different types of parameters are exactly what overloading uses, and methods sharing the same name are the essence of overloading.

Please log in or register to report this question.

Answer: C

The false statement is that polymorphism increases code complexity and reduces flexibility.

Polymorphism lets one interface stand for many implementations: code written against a base class or interface works with any derived type, and new types can be added without changing that code. That makes programs more flexible and easier to extend, the opposite of the statement.

The other three are true. One interface with multiple implementations is the definition. It is achieved by overloading (compile-time) and overriding (runtime), and overriding relies on runtime (dynamic) method binding.

Please log in or register to report this question.

Loading…

Other Subjects

Tags: Polymorphism and Virtual Functions Questions and Answers || Polymorphism and Virtual Functions MCQ Questions and Answers || Polymorphism and Virtual Functions GK Questions and Answers || Polymorphism and Virtual Functions GK MCQ Questions || Polymorphism and Virtual Functions Multiple Choice Questions and Answers || Polymorphism and Virtual Functions GK || GK on Polymorphism and Virtual Functions || Object Oriented Programming Questions and Answers || Object Oriented Programming MCQ Questions and Answers || Object Oriented Programming GK Questions and Answers || GK on Object Oriented Programming