Back to articles
What is Method Overloading in Java?

What is Method Overloading in Java?

via Dev.toSakthi S

Method Overloading In java is a feature that allows a class to have multiple methods with the same name, provide they have different parameter lists It is a form of compile-time polymorphism also known as static polymorphism or early binding Methods can share the same name if their parameter lists differ. Cannot overload by return type alone; parameters must differ. The compiler chooses the most specific match when multiple methods could apply. ` class Product{ public int multiply(int a, int b){ int prod = a * b; return prod; } public int multiply(int a, int b, int c){ int prod = a * b * c; return prod; } } class Geeks{ public static void main(String[] args) { Product ob = new Product(); int prod1 = ob.multiply(1, 2); System.out.println( "Product of the two integer value: " + prod1); int prod2 = ob.multiply(1, 2, 3); System.out.println( "Product of the three integer value: " + prod2); } }` Output Product of the two integer value: 2 Product of the three integer value: 6

Continue reading on Dev.to

Opens in a new tab

Read Full Article
0 views

Related Articles