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
Girish Reddy 52Girish Reddy 52 

Can we override static method in apex ?

Can you please give me an example of that code 
mukesh guptamukesh gupta
Hi Girish,

Yes we can override, Please follow below code

controller2.cls
public class controller2 
{
    public static string method2(string parameter1, string parameter2) {
        // put your static code in here            
        return parameter1+parameter2;
    }
    ...
}
controller1.cls
public class controller1
{
    ...
    public void method1() {
        string returnValue = controller2.method2('Hi ','there');
    }
}

​​​​​​​if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

 
PriyaPriya (Salesforce Developers) 

Hi Girish,

Yes we can overide the static method in apex. For more information refer the below article :- 

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm

 

Also check this similar example :- 

https://salesforce.stackexchange.com/questions/82938/how-do-i-override-an-inherited-static-remote-method-in-apex-or-visualforce

 

If the above information helps you, please mark it as best answer.

Regards,

Priya Ranjan