Skip to main content

Command Palette

Search for a command to run...

Method Overloading

Published
1 min readView as Markdown
Method Overloading

Introduction

  1. Method Overloading basically implies the method with the same name but different functionality.
  2. Since we are having the same then how does the JVM distinguish between functions,It will check the function signature that is the number of parameters, return type

Advantages Of Using Method Overloading

  1. We do not have to remember the function name for every separate function.
  2. Makes code testing and debugging easier

Implementing It Using Java

class HelloWorld {
    public static void main(String[] args) {

        method_overloading object =new method_overloading();
         object.add(10,20);
         object.add(10,20,30);

    }
}


class method_overloading{

public void add(int num1, int num2){
    System.out.println(num1+num2);
}
public void add(int num1, int num2, int num3){
    System.out.println(num1+num2+num3);
}

}

Output is :

Screenshot 2022-12-01 142908.jpg

More from this blog

Jeevan Henry Dsouza's team blog

23 posts