Activity Forums Salesforce® Discussions what is difference between static methods and non static methods in Salesforce?

  • Shubham

    Member
    August 23, 2017 at 8:17 am

    hello Uday

    ****Static Method****

    Static methods can be used without instantiating a new instance of the class.

    public class Utils {
    public static String getHelloWorld() {
    return 'Hello World';
    }
    }

    These methods can be called directly

    String salutation = Utils.getHelloWorld();

    ****Non-Static Method****
    Non-static method  must have a new instance of the class instantiated in order to be used. Typically these rely on data inside the class that then is referred to inside the class

    public class Utils {

    public String getHelloWorld() {
    return 'Hola Mundo';
    }

    This version of the method requires us to create a new instance

    Utils a = new Utils();

    String require =a.getHelloWorld();

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos