Start Coding Now

Method Overloading in Java - Compile-time Polymorphism

Learn about method overloading. How to create multiple methods with the same name but different parameters.

Method Overloading

If a class has multiple methods having same name but different in parameters, it is known as Method Overloading.

Ways to overload:

  • By changing number of arguments.
  • By changing the data type.
  • class Adder {
      static int add(int a, int b) {
         return a + b;
      }
      static double add(double a, double b) {
         return a + b;
      }
    }

    class TestOverloading { public static void main(String[] args) { System.out.println(Adder.add(11, 11)); System.out.println(Adder.add(12.3, 12.6)); } }

    Frequently Asked Questions