+ Start a Discussion
SF YodhaSF Yodha 

can we overload a method in apex with different number of parameters ?

Ashish DevAshish Dev
You can, can you explain what are you trying to achieve?
Manish  ChoudhariManish Choudhari
Hi Yodha,

Yes, you can do that something like below:
public class MethodOverloading {
    public static Integer sum(Integer one, Integer two){
        return one+two;
    public static Integer sum(Integer one, Integer two, Integer three){
        return one+two+three;
    public static Integer sum(Integer one, Integer two, String str){
        return one+two;

The above methods can be called like below:
Integer sum1 = MethodOverloading.sum(10, 15);
Integer sum2 = MethodOverloading.sum(10, 15, 17);
Integer sum3 = MethodOverloading.sum(10, 15, 'Sum Calculated');

Please mark this as best answer if this answers your query.

Check my online presence here: 
My Blog: http://sfdcfacts.com/
Youtube Channel: https://www.youtube.com/SFDCFacts
LinkedIn: https://www.linkedin.com/in/manish-choudhary/
Trailhead: https://trailhead.salesforce.com/en/me/manish-choudhari
Twitter: https://mobile.twitter.com/manish_sfdc