English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Method overloading is a form of static polymorphism. In method overloading, we can define multiple methods with the same name but different parameters. See the following example program.
public class Tester { public static void main(String args[]) { Tester tester = new Tester(); System.out.println(tester.add(1, 2)); System.out.println(tester.add(1, 2,3)); } public int add(int a, int b) { return a + b; } public int add(int a, int b, int c) { return a + b + c; } }
Output result
3 6
In this case, we use a methodadd()
This method can use two or three parameters and perform operations accordingly. This is called method overloading or static polymorphism.