Civil Service Hospital2080 BSQuestion 7 of 10
What is polymorphism? What are its types? Explain any one with example.
10 marks
Question source
- Exam year
- 2080 BS / 2023 AD
- Level
- Level 5 (Prabidhik, Engineering and Maintenance, Computer Technician)
- Paper
- Paper II – Technical Subject
- Section
- Section B
Model answer
Polymorphism (many forms) lets one name behave differently — one interface, multiple implementations. Consistent with SI-paper terminology.
Types:
- Compile-time (overloading) — Same method, different parameters; choice at compile time.
- Runtime (overriding) — Child redefines parent method; choice at runtime via dynamic dispatch.
Example — runtime overriding (Java):
class Staff { void pay(){ System.out.println("Basic"); } }
class Doctor extends Staff { void pay(){ System.out.println("Doctor+allowance"); } }
Staff s = new Doctor(); s.pay(); // prints Doctor+allowance
Same call pay() gives different result by object. Benefit: processBill() works for OPD, Lab and Pharmacy objects without rewriting caller — extensible hospital modules.