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

Query on Declare variable




Integer i;


Public Integer i;


What is the difference between above two declaration..




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






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".