Hackforge Academy

Category: java

Polymorphism

Published on 22 Feb 2026

Explanation


Compile-time polymorphism is achieved
using method overloading.

Code:

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

Explanation


Runtime polymorphism is achieved using
method overriding.

Code:

class A { void show() { System.out.println("A"); } }
class B extends A { void show() { System.out.println("B"); } }

Explanation


In compile-time polymorphism, method
resolution happens at compile time.

Code:

Calculator c = new Calculator();
c.add(10, 20);

Explanation


In runtime polymorphism, method call
depends on object type at runtime.

Code:

A obj = new B();
obj.show();

Explanation


Overloading requires different method signatures.

Code:

void print(int a) {}
void print(String a) {}

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community