Home »
Aptitude Questions and Answers »
C++ Aptitude Questions and Answers
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++?
- Polymorphism is one of the most important concepts of oops.
- Polymorphism is a greek word which means many forms.
- Polymorphism is used to create a new class by inheriting feature of existing class.
- C++ does not support polymorphism.
Options:
- A and B
- A and C
- A, B, and D
- A, B, C, and D
Correct Answer - 1
A and B
Explanation:
Statements A and B are correct about polymorphism in C++.
2) Which of the following are the types of polymorphism?
- User define polymorphism
- System define polymorphism
- Static polymorphism
- Dynamic polymorphism
Options:
- A and B
- C and D
- A, C, and D
- A, B, C, and D
Correct Answer - 2
C and D
Explanation:
Options C and D are correct types of polymorphism.
3) The function overloading is the type of runtime polymorphism?
- Yes
- No
Correct Answer - 2
No
Explanation:
No, the function overloading is the type of compile time polymorphism.
4) The dynamic polymorphism is also known as runtime polymorphism?
- Yes
- No
Correct Answer - 1
Yes
Explanation:
Yes, dynamic polymorphism is also known as runtime polymorphism.
5) Which of the following are the types of overloading in C++?
- Function overloading
- Namespace overloading
- Class overloading
- Operator overloading
Options:
- A and B
- C and D
- A and D
- A, B, C, and D
Correct Answer - 3
A and D
Explanation:
The function and operator overloading are the types of overloading used in C++.
6) There are the following statements that are given below, which of them are correct about function overloading in C++?
- Function overloading is the type of static time polymorphism.
- Function overloading is the type of run time polymorphism.
- Function overloading is used to create multiple functions with the same name.
- We can perform function overloading on non member function in C++.
Options:
- A and B
- B, C, and D
- A, B, and D
- A, C, and D
Correct Answer - 4
A, C, and D
Explanation:
Statements A, C, and D are correct about function overloading in C++.
7) How can we implement function overloading in C++?
- Using types of different arguments.
- Using number of arguments.
- Using order of arguments.
- All of the above
Options:
- A and B
- B and C
- A and C
- D
Correct Answer - 4
D
Explanation:
All given options are correct about implementation of function overloading.
8) To implement function overloading we need to include "funover.h" header in our program?
- Yes
- No
Correct Answer - 2
No
Explanation:
No, there is no need to include "funover.h" header in our program.
9) We can overload only virtual functions?
- Yes
- No
Correct Answer - 2
No
Explanation:
No, there is no need of virtual keyword to implement function overloading.
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:
- Syntax error
- * @
- Runtime error
- Linker error
Correct Answer - 2
* @
Explanation:
The above program will print "* @" on the console screen.
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:
- Syntax error
- * @
- Runtime error
- Linker error
Correct Answer - 2
* @
Explanation:
The above program will print "* @" on the console screen.
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:
- Syntax error
- Runtime error
- Linker error
- @ @ # # #
Correct Answer - 4
@ @ # # #
Explanation:
The above program will print "@ @ # # # " on the console screen.
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:
- Syntax error
- Runtime error
- Linker error
- @ @
Correct Answer - 1
Syntax error
Explanation:
The following error occurs,
main.cpp: In function ‘int printChar(int, char)’:
main.cpp:12:5: error: ambiguating new declaration of ‘int printChar(int, char)’
int printChar(int num, char ch)
^~~~~~~~~
main.cpp:4:6: note: old declaration ‘void printChar(int, char)’
void printChar(int num, char ch)
^~~~~~~~~
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:
- Syntax error
- @ @ # # #
- Runtime error
- Linker error
Correct Answer - 2
@ @ # # #
Explanation:
The above program will print "@ @ # # # " on the console screen.
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:
- $->20
- #->20
- Syntax error
- Runtime error
Correct Answer - 1
$->20
Explanation:
The above program will print "$->20" on the console screen.
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:
- $->20
- #->20
- Syntax error
- Runtime error
Correct Answer - 2
#->20
Explanation:
The above program will print "#->20" on the console screen.
17) Can we overload class constructors?
- Yes
- No
Correct Answer - 1
Yes
Explanation:
Yes, we can overload class constructors.
18) Can we overload class destructors?
- Yes
- No
Correct Answer - 2
No
Explanation:
No, we cannot class destructors.
19) What are the main causes of ambiguity in function overloading?
- Type conversion
- Functions with default arguments
- Functions with call by reference
- None of the above
Options:
- A and B
- B and C
- A and C
- D
Correct Answer - 4
D
Explanation:
All given options are causes of ambiguity in function overloading.
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:
- $->20
- #->20
- Syntax error
- Runtime error
Correct Answer - 1
$->20
Explanation:
The above program will print "$->20" on the console screen.