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

Which of the following is not true about constructor

The correct answer is
They can be virtual.

This question asks to identify the statement that is NOT true about constructors in programming, likely C++.

Constructor Properties Analysis

Let's analyze each statement regarding constructors:

  • Statement 1: "When an object is created and initialized at the same time, a copy constructor gets called."

    This statement is generally true. Copy constructors are invoked when a new object is initialized from an existing object of the same type, often during object creation or function calls passing objects by value.

  • Statement 2: "They do not have return types, not even void."

    This statement is true. Constructors are special member functions that do not return any value and cannot be declared with a return type, including $void$.

  • Statement 3: "They can be virtual."

    This statement is false. Constructors cannot be declared as $virtual$. Virtual functions are related to polymorphism and dynamic dispatch, concepts that do not apply to constructors because they are called explicitly during object creation, not through a base class pointer or reference.

  • Statement 4: "They can not be inherited, though a derived class can call the base class constructor."

    This statement is true. Constructors are not inherited by derived classes. However, a derived class constructor is responsible for initializing the base class part of the object, and it does so by explicitly calling the base class constructor.

Conclusion on Constructor Truthfulness

Based on the analysis, the statement "They can be virtual" is the one that is NOT true about constructors.

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. 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:
  3. 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 :

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

  5. Which of the following is not correct for virtual function 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