Lab P10 β€” Demonstrate compile-time polymorphism.

NBC351 Β· Program 10⏱ 8 min read❓ 5 MCQs

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: hi

Explanation

  • show() overloaded by parameter type.
  • Resolved at compile time.

Viva / Important Questions

Short Questions

  1. What is compile-time polymorphism?
  2. How overloading resolved?

Long Questions

  1. Explain the program in detail.
  2. 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.