Back to the 2023 paper

Module III: Basics of Web Programming

20232m

What is polymorphism?

Worked SolutionAI Assisted

Polymorphism means "many forms": one interface or method name behaving differently depending on the object or arguments.

1. Compile-time (static): method overloading, where the same name has different parameter lists.

int add(int a, int b) { return a + b; }
double add(double a, double b) { return a + b; }

2. Runtime (dynamic): method overriding, where the subclass redefines a parent method and the JVM picks the version from the actual object type.

Animal a = new Dog();
a.sound();   // calls Dog's sound()

It makes code flexible and extensible.

Similar questions

Student FinanceWeb Platform

Pocketly — Personal Finance for Students

Keep your hostel and college expenses under control. Track accounts, log spending in seconds, and stay within your monthly budget.