function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ 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:
Youtube Channel: