All Exams Test series for 1 year @ ₹349 only
Question

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

(a) Overloading a function 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 executed then constructor of a base class is executed.

(d) Overloading is a type of polymorphism.

Choose the correct option from those given below:

The correct answer is

(b) and (d) only

Analyzing C++ and Object-Oriented Programming Statements

Let's carefully examine each statement provided regarding C++ and its object-oriented programming features to determine their accuracy.

  • Statement (a): Overloading a function gives the capability to an existing operator to operate on other data types.

    This statement is incorrect. The capability for an existing operator (like +, -, ==) to operate on user-defined data types (like objects of a class) is provided by operator overloading. Function overloading, on the other hand, allows multiple functions to have the same name within the same scope, provided they have different parameter lists (different number or types of arguments).

  • Statement (b): Inheritance in object-oriented programming provides support to reusability.

    This statement is correct. Inheritance is a fundamental concept in object-oriented programming (OOP) where a new class (called the derived or child class) is created from an existing class (the base or parent class). The derived class inherits properties (data members) and behaviors (member functions) of the base class. This allows code written for the base class to be reused by the derived class, reducing redundancy and promoting efficiency in software development.

  • Statement (c): When object of a derived class is defined, first the constructor of derived class is executed then constructor of a base class is executed.

    This statement is incorrect. When an object of a derived class is created, the base class constructor is always executed first, followed by the derived class constructor. This ensures that the base class part of the derived object is properly initialized before the derived class adds its own initialization.

  • Statement (d): Overloading is a type of polymorphism.

    This statement is correct. Polymorphism means "many forms". In C++, polymorphism allows objects of different classes to be treated as objects of a common base class. Overloading (both function overloading and operator overloading) is a form of polymorphism known as compile-time polymorphism or static polymorphism. It is resolved at compile time based on the function signature or operator usage.

Identifying True Statements

Based on our analysis:

  • Statement (a) is False.
  • Statement (b) is True.
  • Statement (c) is False.
  • Statement (d) is True.

Therefore, the true statements are (b) and (d) only.

Revision Table: C++ OOP Concepts

Concept Description Relevance to Statements
Function Overloading Multiple functions with the same name but different parameters. Statement (a) incorrectly describes this.
Operator Overloading Giving existing operators new meanings for user-defined types. Related to Statement (a).
Inheritance Creating new classes from existing ones, inheriting features. Statement (b) correctly identifies its role in reusability.
Constructor Execution (Derived Class) Order of constructor calls: Base class first, then Derived class. Statement (c) is incorrect about this order.
Polymorphism Ability to take on multiple forms (e.g., overloading, overriding). Statement (d) correctly identifies overloading as a type of polymorphism.

Additional Information on C++ Concepts

Understanding the core principles of Object-Oriented Programming (OOP) is crucial for mastering C++. Let's delve a bit deeper into the concepts discussed:

  • Reusability through Inheritance:

    Imagine you have a base class Vehicle with properties like speed and functions like start(). You can create a derived class Car or Bike that inherits from Vehicle. Car and Bike automatically get the speed property and the start() function without rewriting the code. They can then add their own specific features, like number of wheels or steering type. This saves time and makes code easier to maintain.

  • Constructor Execution Order:

    The reason the base class constructor runs first is logical. A derived class object contains a 'part' that is essentially a base class object. This base class part must be fully set up and initialized before the derived class can initialize its own specific members, which might rely on the base class being ready.

  • Types of Polymorphism:

    C++ supports two main types of polymorphism:

    • Compile-time Polymorphism (Static Binding): This is resolved at compile time. Examples include Function Overloading and Operator Overloading. The compiler knows which function or operator to call based on the signature or context.
    • Run-time Polymorphism (Dynamic Binding): This is resolved at run time. The most common example is Function Overriding using virtual functions. The actual function called depends on the type of the object being pointed to by a base class pointer or reference at runtime.

These concepts—Inheritance for reusability and Polymorphism (including overloading) for flexibility—are cornerstones of effective C++ programming.

Was this answer helpful?

Important Questions from OOPs concept

  1. Let A be the base class in C++ and B be the derived class from A with protected inheritance. Which of the following statement is false for class B?

  2. Match List I with List II

    List IList II
    (Programming Paradigm)(Characteristic)
    A.ImperativeI.Declarative, clausal representation, theorem proving
    B.Object‐orientedII.Side‐effect free, declarative, expression evaluation
    C.LogicIII. Imperative, abstract data type
    D.FunctionalIV.Command‐based, procedural

    Choose the correct answer from the options given below :

  3. A member function can always access the data in _______, (in C++).

  4. Which of the following is not correct for virtual function in C++?

  5. Which of the following is correct (in C++)?

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App