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 

What is variable and constants in apex what is difference between them

Ranjeet Singh (SFDC Developer)Ranjeet Singh (SFDC Developer)

The main diffrence between variable and Constant.

Variable: Varaible value can be change any time. it cant be fix.

 

Constant: Constant value can not be change. Constants can be defined using the final keyword, which means that the variable can be assigned at most once, either in the declaration itself, or with a static initializer method if the constant is defined in a class.

 

How to declare Variable and Constant:

Varaible:

Public Integer fstNumber;

 

Constant:

static final Integer fstNumber=10;

     OR

static final Integer fstNumber;

static{

            fstNumber=10;

}