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
ShravanKumarBagamShravanKumarBagam 

Query on Declare variable

Hi,

 

 

Integer i;

 

Public Integer i;

 

What is the difference between above two declaration..

BewitchedBewitched

Hi,

 

Integer i is a local variable, where as a public integer i can be used by the class in which it is declared.

 

http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_variables.htm

 

 

Thanks,

Tulika

sfdcfoxsfdcfox

The first definition, "integer I", can mean either (a) a variable in the current function's scope or (b) a private member of a class. The former occurs when it is written inside of a function's body, while the latter occurs when it is written outside of any function's body.

 

public class myClass {
  integer i; // private class member

  public void func() {
    integer i; // local function member i;
    this.i = i; // local i shadows class i, so use this to access it.
  }

  public void func2() {
    i = 5; // there is no shadow, i do not need "this".
  }
}