+ 3

Method overloading

What is the advantage of method overloading ?

19th Nov 2018, 10:27 AM
Shalini R
Shalini R - avatar
4 odpowiedzi
+ 3
Tom is right, in addition I would say "you can also call the same method using different number of parameters".
19th Nov 2018, 3:44 PM
Timur Myngbay
Timur Myngbay - avatar
+ 4
The main advantage is the flexibility to use a similar method with different types of values.
19th Nov 2018, 12:11 PM
Tom Dooley
Tom Dooley - avatar
+ 3
The method could then accepts more than one type of arguments. For example, you wrote a method called: add(a, b) => if you overload the method (wrote several different methods with the same name) to accept types of Integer, Double and String. Your method now is capable of receiving input as integer, double, String and behave differently with each type of input.
20th Nov 2018, 7:37 PM
Quang Tran
Quang Tran - avatar