Lab P10 β Demonstrate compile-time polymorphism.
Aim
Aim: Demonstrate compile-time polymorphism (overloading).
Theory
Demonstrate compile-time polymorphism (overloading).
C++ Program
#include
using namespace std;
class Print {
public:
void show(int x){ cout<<"int: "< Expected Output
int: 5
double: 3.14
string: hiExplanation
- show() overloaded by parameter type.
- Resolved at compile time.
Viva / Important Questions
Short Questions
- What is compile-time polymorphism?
- How overloading resolved?
Long Questions
- Explain the program in detail.
- Discuss key concepts demonstrated.
MCQ Practice
1. Compile-time polymorphism via:
- Overloading
- Virtual functions
- Inheritance
- Templates
Answer: Overloading.
2. Resolution at:
- Compile time
- Run time
- Link time
- Never
Answer: Compile time.
3. Overloading based on:
- Param types
- Return type only
- Name
- Access
Answer: Param types.
4. Also called:
- Static binding
- Dynamic binding
- Late binding
- None
Answer: Static binding.
5. Virtual functions give:
- Run-time polymorphism
- Compile-time
- None
- Both
Answer: Run-time polymorphism.
Quick Revision
- Overloading = compile-time polymorphism.
- Static binding.