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

Budget AppAndroid App

Pocketly on Android

Log daily food, travel, and hostel expenses instantly. Set monthly spending limits and see where your money goes without complex spreadsheets.