Overloading is selected from compile-time signatures, while overriding dispatches from the runtime object. Keeping those mechanisms separate makes polymorphic calls predictable.
A strong polymorphism example uses a parent reference such as Shape, Payment, or Notification and then calls the same method on different child objects. The result proves that runtime behavior depends on the actual object.
Overloading chooses a method at compile time based on the method name and parameter list.
class Printer {
void print(String text) {
System.out.println(text);
}
void print(int number) {
System.out.println(number);
}
}
Overriding chooses the method implementation at runtime based on the actual object type.
class Payment {
void pay(double amount) {
System.out.println("Generic payment: " + amount);
}
}
class UpiPayment extends Payment {
@Override
void pay(double amount) {
System.out.println("UPI paid: " + amount);
}
}
public class PolymorphismDemo {
public static void main(String[] args) {
Payment payment = new UpiPayment();
payment.pay(500);
}
}
Interfaces make polymorphism more flexible because unrelated classes can implement the same contract.
interface Notifier {
void send(String message);
}
class EmailNotifier implements Notifier {
public void send(String message) {
System.out.println("Email: " + message);
}
}
class SmsNotifier implements Notifier {
public void send(String message) {
System.out.println("SMS: " + message);
}
}
Method overloading is resolved by the compiler using the method name and parameter list. Method overriding is resolved at runtime using the actual object type, which is why parent references can call child behavior.
The actual object type, not the reference variable type.
No. The compiler selects an overload from the declared argument types.
It stores a subclass object in a superclass reference, preserving access to overridden behavior.
Practice, interview questions, and compiler links for Core Java.
Finish the concept here, then reinforce it with hands-on coding, interview prep, or a tool that matches the topic.
Explore 500+ free tutorials across 20+ languages and frameworks.
Fresh tutorials, interview guides, and coding practice in your inbox.