Which of the following statements are true regarding C++? (a) Overloading…

2019

Which of the following statements are true regarding C++?

(a) Overloading gives the capability to an existing operator to operate on other data types

(b) Inheritance in object oriented programming provides support to reusability

(c) When object of a derived class is defined, first the constructor   of derived class is excecuted then constructor of a base class is executed    

(d) Overloading is a type of polymorphism

Choose the correct option from those given below:

Answer: C. (a), (b) and (d) onlyCorrect statements: Overloading gives the capability to an existing operator to operate on other data types; Inheritance provides support to reusability;…

  1. A.

    (a) and (b) only

  2. B.

    (a), (b) and (c)  only

  3. C.

    (a), (b) and (d) only

  4. D.

    (b), (c) and (d) only

Attempted by 121 students.

Show answer & explanation

Correct answer: C

Correct statements: Overloading gives the capability to an existing operator to operate on other data types; Inheritance provides support to reusability; Overloading is a type of polymorphism.

  • Overloading allows operators/functions to work with other data types: True. Operator overloading (and function overloading) lets you define how operators or functions behave for user-defined types or other type combinations, enabling the same operator/function name to be applied to different types.

  • Inheritance provides support to reusability: True. Inheritance allows derived classes to reuse and extend code (data members and member functions) from base classes, promoting code reuse and extension.

  • Overloading is a type of polymorphism: True. Overloading is an example of compile-time (static) polymorphism, where the compiler resolves which function or operator version to call based on argument types or number at compile time. This contrasts with runtime (dynamic) polymorphism achieved through virtual functions.

Incorrect statement: The claim that the derived-class constructor is executed first and then the base-class constructor is false.

  • Constructor execution order explanation: When an object of a derived class is created, the base-class constructor runs first to initialize the base part of the object, and then the derived-class constructor runs to initialize the derived part. This ensures proper initialization of base class members before derived-class initialization.

Summary: The true statements are the ones describing operator/function overloading (allowing operators to work with other data types), inheritance enabling reusability, and overloading being a form of polymorphism. The statement about constructor order is incorrect.

A video solution is available for this question — log in and enroll to watch it.

Explore the full course: Mppsc Assistant Professor Computer Science Paper 2

Loading lesson…