Javarevisited Newsletter

Javarevisited Newsletter

Master Java Polymorphism: Method Overloading vs Overriding Explained

Master Java Polymorphism: Method Overloading vs Overriding Explained

javinpaul's avatar
javinpaul
Aug 02, 2026
∙ Paid

Before we dive in, if you're preparing for Java interviews, you may also want to check out my books, Grokking the Java Interview and Grokking the Spring Boot Interview. They cover hundreds of frequently asked interview questions, detailed explanations, interview tips, and practical examples to help you prepare with confidence. As a reader of this blog, you can use the coupon code FRIENDS20 to get 20% off your purchase. And, if you love kindle edition check it here

Hello guys, Method overloading and method overriding are two of the most fundamental concepts in Java, yet they are also among the most commonly confused topics for beginners. Both allow you to define methods with the same name, but they serve very different purposes and are resolved at different stages of program execution.

Simply put, method overloading lets you create multiple methods with the same name in the same class, provided they have different parameter lists.

Method overriding, on the other hand, allows a subclass to provide its own implementation of a method already defined in its parent class. Together, these two features are powerful examples of polymorphism, one of the core principles of object-oriented programming.

The biggest difference between them is when Java decides which method to call. Overloaded methods are resolved at compile time using static binding, whereas overridden methods are resolved at runtime using dynamic binding.

This distinction has a significant impact on how Java applications behave and is a favorite topic in technical interviews.

There are also several important rules to remember. For example, private, static, and final methods cannot be overridden, although they can still be overloaded. Likewise, an overridden method must keep the same method signature as the parent method, while an overloaded method must have a different parameter list.

Because of their importance in object-oriented programming, understanding the differences between method overloading and method overriding is essential for every Java developer. It’s also one of the most frequently asked Java interview questions, appearing in interviews ranging from entry-level developer roles to senior Java positions.

In this article, we’ll compare method overloading vs. method overriding side by side, explain how each works with practical examples, and discuss the key differences, rules, and interview points you should know.

By the way, If you're serious about cracking Java interviews, I've put together two comprehensive guides—Grokking the Java Interview and Grokking the Spring Boot Interview. These books include hundreds of real interview questions, in-depth explanations, coding tips, and common pitfalls to help you prepare for both beginner and experienced Java roles. As a special bonus for my readers, you can use the coupon code FRIENDS20 to receive 20% off.

How Method Overloading Works in Java?

Method overloading allows you to declare multiple methods with the same name in the same class, provided each method has a different parameter list.

Java distinguishes overloaded methods based on their method signature, which includes:

  • Number of parameters

  • Parameter types

  • Order of parameters (when types differ)

The return type is not part of the method signature, so simply changing the return type does not create an overloaded method.

Method overloading is resolved during compile time, also known as static binding.

One important point is that static, private, and final methods can all be overloaded, even though they cannot be overridden.

In our example of the Loan and PersonalLoan class, createLoan method is overloaded. Since you have two crateLoan() methods with one takes one argument lender while the other take two arguments both lender and interestRate.

Remember you can overload static methods in Java, you can also overload a private and final method in Java but you can not override them.

How to Override a Method in Java?

Method overriding allows a subclass to provide its own implementation of a method already defined in its parent class.

For a method to be overridden:

  • The subclass must extend the parent class.

  • The method name and parameter list must remain the same.

  • The return type must be compatible (covariant return types are supported since Java 5).

Unlike overloading, overriding is resolved at runtime using dynamic binding. This enables Java’s runtime polymorphism, where the actual object—not the reference type—determines which implementation is executed.

Methods declared as private, static, or final cannot be overridden.

For example in our case when we call personalLoan.toString() method even though personalLoan object is of type Loan actual method called would be from PersonalLoan class because object referenced by personalLoan variable is of type PersonalLoan().

This is a very useful technique to modify the behavior of a function in Java based on different implementations. equals(), hashcode() and compareTo() methods are classic example of overridden methods in Java.

By the way, as part of overriding best practice, always use @Override annotation, while overriding method from an abstract class or interface.

Rules of Method Overriding in Java

  • Method signature must remain the same.

  • Return type must be the same or covariant.

  • Access level cannot be reduced.

  • Checked exceptions cannot be broader than the parent method.

  • Private, static and final methods cannot be overridden.

  • Always use the @Override annotation to let the compiler verify your implementation.

Difference between Method Overloading vs Overriding in Java

Overloading vs Overriding in Java is one of the popular java interview questions at many companies and asked at different levels of programmers. Here are some important differences between overloading and overriding in Java.

Though It’s more important is to understand how to use both overloading and overriding, these difference are good from the interview perspective and gives some basic idea as well:

1) First and most important difference between method overloading and overriding is that In the case of method overloading in Java, the signature of the method changes while in the case of method overriding it remains the same.

2) Second major difference between method overloading vs overriding in Java is that You can overload the method in one class but overriding can only be done on the subclass.

3) You can not override static, final, and private methods in Java but you can overload static, final, or private methods in Java.

4) Overloaded method in Java is bonded by static binding and overridden methods are subject to the dynamic binding.

5) Private and final method can also be not overridden in Java.

By the way, you might have heard about “a picture is worth more than a thousand words” and this is made true by the following image. By looking at the pic you can clearly understand the difference between method overloading and overriding in Java.

Handling Exception while overloading and overriding method in Java

While overriding a method it can only throw checked exception declared by overridden method or any subclass of it, which means if the overridden method throws IOExcpetion then the overriding method can throw sub classes of IOExcpetion like FileNotFoundException but not wider exception like Exception or Throwable.

This restriction is only for checked Exception for RuntimeException you can throw any RuntimeException. The overloaded method in Java doesn’t have such restrictions and you are free to modify the throws clause as per your need.

Method Overloading and Overriding Example in Java

Here is an example of both method overloading and method overriding in Java. In order to explain the concept, we have created two classes Loan and PersonalLoan. createLoan() method is overloaded as it has different versions with a different signature, while toString() method which is original declared in Object class is overridden in both Loan and PersonalLoan class.

public class OverloadingOverridingTest {

    public static void main(String[] args) {

        // Example of method overloading in Java
        Loan cheapLoan = Loan.createLoan(“HSBC”);
        Loan veryCheapLoan = Loan.createLoan(“Citibank”, 8.5);

        // Example of method overriding in Java
        Loan personalLoan = new PersonalLoan();
        personalLoan.toString();
    }

}

public class Loan {
    private double interestRate;
    private String customer;
    private String lender;

    public static Loan createLoan(String lender) {
        Loan loan = new Loan();
        loan.lender = lender;
        return loan;
    }

    public static Loan createLoan(String lender, double interestRate) {
        Loan loan = new Loan();
        loan.lender = lender;
        loan.interestRate = interestRate;
        return loan;
    }

    @Override
    public String toString() {
        return “This is Loan by Citibank”;
    }

}

public class PersonalLoan extends Loan {

    @Override
    public String toString() {
        return “This is Personal Loan by Citibank”;
    }
}

Things to Remember

1) In the case of method overloading method signature gets changed while in case of overriding signature remains the same.

2) Return type is not part of the method signature in Java.

3) Overloaded method can be subject to compile-time binding but the overridden method can only be bind at run-time.

4) Both overloaded and overridden method has the same name in Java.

5) Static method can not be overridden in Java.

6) Since the private method is also not visible outside of class, it can not be overridden and method binding happens during compile time.

7) From Java 5 onwards you can use annotation in Java to declare overridden method just like we did with @Override. @override annotation allows compiler, IDE like NetBeans and Eclipse to cross-verify or check if this method is really overridden super class method or not.

Bonus: Covariant Return Types (Java 5+)

Since Java 5, an overridden method can return a subclass of the original return type.

class Animal {}

class Dog extends Animal {}

class AnimalFactory {
    Animal create() {
        return new Animal();
    }
}

class DogFactory extends AnimalFactory {

    @Override
    Dog create() {
        return new Dog();
    }
}

This is called Covariant Return Type, and it improves type safety by eliminating unnecessary casts.

Java Interview Tips

Remember these five facts:

  • Return type alone cannot overload a method.

  • Constructors can be overloaded.

  • Constructors cannot be overridden.

  • Static methods are hidden, not overridden.

  • Private methods cannot participate in polymorphism.

And, If you're preparing for Java interviews, I also recommend checking out my books, Grokking the Java Interview and Grokking the Spring Boot Interview. They contain hundreds of carefully selected interview questions, practical examples, and expert tips gathered from years of interviewing and mentoring Java developers. As a thank-you for being a reader, you can use the coupon code FRIENDS20 to enjoy a 20% discount.

Final Thoughts

Method overloading and method overriding are two fundamental Java concepts that every developer should understand. Although both allow methods to share the same name, they solve different problems.

  • Use method overloading when you want multiple ways to perform a similar operation with different inputs.

  • Use method overriding when you want subclasses to provide specialized behavior while preserving a common interface.

Understanding the difference not only helps you write cleaner object-oriented code but also prepares you for one of the most frequently asked Java interview questions.

As I said one a good example of this is overriding the clone method and using return type as Actual type instead of java.lang.Object, which is suggested by Joshua Bloch in Effective Java as well.

User's avatar

Continue reading this post for free, courtesy of javinpaul.

Or purchase a paid subscription.
© 2026 javinpaul · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture