C++ Polymorphism & Function Overloading Aptitude Questions and Answers

C++ Polymorphism & Function Overloading Aptitude: This section contains C++ Polymorphism & Function Overloading Aptitude Questions and Answers with explanations.
Submitted by Nidhi, on March 01, 2021

1) There are the following statements that are given below, which of them are correct about polymorphism in C++?

  1. Polymorphism is one of the most important concepts of oops.
  2. Polymorphism is a greek word which means many forms.
  3. Polymorphism is used to create a new class by inheriting feature of existing class.
  4. C++ does not support polymorphism.

Options:

  1. A and B
  2. A and C
  3. A, B, and D
  4. A, B, C, and D

2) Which of the following are the types of polymorphism?

  1. User define polymorphism
  2. System define polymorphism
  3. Static polymorphism
  4. Dynamic polymorphism

Options:

  1. A and B
  2. C and D
  3. A, C, and D
  4. A, B, C, and D

3) The function overloading is the type of runtime polymorphism?

  1. Yes
  2. No

4) The dynamic polymorphism is also known as runtime polymorphism?

  1. Yes
  2. No

5) Which of the following are the types of overloading in C++?

  1. Function overloading
  2. Namespace overloading
  3. Class overloading
  4. Operator overloading

Options:

  1. A and B
  2. C and D
  3. A and D
  4. A, B, C, and D

6) There are the following statements that are given below, which of them are correct about function overloading in C++?

  1. Function overloading is the type of static time polymorphism.
  2. Function overloading is the type of run time polymorphism.
  3. Function overloading is used to create multiple functions with the same name.
  4. We can perform function overloading on non member function in C++.

Options:

  1. A and B
  2. B, C, and D
  3. A, B, and D
  4. A, C, and D

7) How can we implement function overloading in C++?

  1. Using types of different arguments.
  2. Using number of arguments.
  3. Using order of arguments.
  4. All of the above

Options:

  1. A and B
  2. B and C
  3. A and C
  4. D

8) To implement function overloading we need to include "funover.h" header in our program?

  1. Yes
  2. No

9) We can overload only virtual functions?

  1. Yes
  2. No

10) What is the correct output of the given code snippets?

#include <iostream>
using namespace std;

void printChar()
{
    cout << "*" <<" ";
}

void printChar(char ch)
{
    cout << ch <<" ";
}

int main()
{
    printChar();
    printChar('@');
    return 0;
}

Options:

  1. Syntax error
  2. * @
  3. Runtime error
  4. Linker error

11) What is the correct output of the given code snippets?

#include <iostream>
using namespace std;

void printChar()
{
    cout << "*"
         << " ";
}

int printChar(char ch)
{
    cout << ch << " ";
}

int main()
{
    printChar();
    printChar('@');
    return 0;
}

Options:

  1. Syntax error
  2. * @
  3. Runtime error
  4. Linker error

12) What is the correct output of given code snippets?

#include <iostream>
using namespace std;

void printChar(int num, char ch)
{
    int i = 0;

    for (i = 0; i < num; i++)
        cout << ch << " ";
}

int printChar(char ch, int num)
{
    int i = 0;

    for (i = 0; i < num; i++)
        cout << ch << " ";
}

int main()
{
    printChar(2, '@');
    printChar('#', 3);
    return 0;
}

Options:

  1. Syntax error
  2. Runtime error
  3. Linker error
  4. @ @ # # #

13) What is the correct output of given code snippets?

#include <iostream>
using namespace std;

void printChar(int num, char ch)
{
    int i = 0;

    for (i = 0; i < num; i++)
        cout << ch << " ";
}

int printChar(int num, char ch)
{
    int i = 0;

    for (i = 0; i < num; i++)
        cout << ch << " ";
}

int main()
{
    printChar(2, '@');
    return 0;
}

Options:

  1. Syntax error
  2. Runtime error
  3. Linker error
  4. @ @

14) What is the correct output of the given code snippets?

#include <iostream>
using namespace std;

class Sample {
public:
    void printChar(int num, char ch)
    {
        int i = 0;

        for (i = 0; i < num; i++)
            cout << ch << " ";
    }

    void printChar(char ch, int num)
    {
        int i = 0;

        for (i = 0; i < num; i++)
            cout << ch << " ";
    }
};

int main()
{
    Sample S;

    S.printChar(2, '@');
    S.printChar('#', 3);

    return 0;
}

Options:

  1. Syntax error
  2. @ @ # # #
  3. Runtime error
  4. Linker error

15) What is the correct output of the given code snippets?

#include <iostream>
using namespace std;

class Sample {
public:
    void print(int num)
    {
        cout << "#->" << num;
    }

    void print(long num)
    {
        cout << "$->" << num;
    }
};

int main()
{
    Sample S;

    S.print(20L);

    return 0;
}

Options:

  1. $->20
  2. #->20
  3. Syntax error
  4. Runtime error

16) What is the correct output of the given code snippets?

#include <iostream>
using namespace std;

class Sample {
public:
    void print(int num)
    {
        cout << "#->" << num;
    }

    void print(long num)
    {
        cout << "$->" << num;
    }
};

int main()
{
    Sample S;

    S.print(20);

    return 0;
}

Options:

  1. $->20
  2. #->20
  3. Syntax error
  4. Runtime error

17) Can we overload class constructors?

  1. Yes
  2. No

18) Can we overload class destructors?

  1. Yes
  2. No

19) What are the main causes of ambiguity in function overloading?

  1. Type conversion
  2. Functions with default arguments
  3. Functions with call by reference
  4. None of the above

Options:

  1. A and B
  2. B and C
  3. A and C
  4. D

20) What is the correct output of the given code snippets?

#include <iostream>
using namespace std;

class Sample {
public:
    void print(int num)
    {
        cout << "#->" << num;
    }

    void print(long num) const
    {
        cout << "$->" << num;
    }
};

int main()
{
    Sample S;

    S.print(20L);

    return 0;
}

Options:

  1. $->20
  2. #->20
  3. Syntax error
  4. Runtime error





Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.