+ Start a Discussion
vutukuru balajivutukuru balaji 

static keyword usage

Public Class Example
public static Integer a;
public integer b;
public Example()
public void add()
System.debug('a value is '+a);
System.debug('b value is '+b);

in the anonymous class

Example e1= new Example();
Example e2= new Example();

what is use of static keyword???????????
Qiu YueNvQiu YueNv
Please refer to the documentation:
PratikPratik (Salesforce Developers) 
Hi Vutukuru,

The static variable will carry it's value through the program, as Qiu mentikoned the link of article:

Static methods, variables, or initialization code are associated with a class, and are only allowed in outer classes. When you declare a method or variable as static, it's initialized only once when a class is loaded. Static variables aren't transmitted as part of the view state for a Visualforce page.

Instance methods, member variables, and initialization code are associated with a particular object and have no definition modifier. When you declare instance methods, member variables, or initialization code, an instance of that item is created with every object instantiated from the class.

Local variables are associated with the block of code in which they are declared. All local variables should be initialized before they are used.