---
schema_version: "1"
id: 770877d5e82d55fe29f8a0235e85661f8c340aa3704ad7cc3329107babffe34e
title: Constants
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/langCon_apex_constants.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_constants.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 368401f21c2d6607abaad11b006d494b1620c9c28d3b1ac6812442e1699b3473
description: Apex constants are variables whose values don’t change after being initialized once. Constants can be defined using the final keyword.
---
# Constants

Apex constants are variables whose values don’t change after being initialized once. Constants can be defined using the final keyword.

The final keyword 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. This example declares two constants. The first is initialized in the declaration statement. The second is assigned a value in a static block by calling a static method.

public with sharing class myCls {
   static final Integer PRIVATE\_INT\_CONST = 200;
   static final Integer PRIVATE\_INT\_CONST2; 

   public static Integer calculate() {
       return 2 + 7;
   }

   static {
       PRIVATE\_INT\_CONST2 = calculate();
   }
}

For more information, see [Using the final Keyword](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_final.htm).

- [← Previous](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_variables.htm "Variables")
- [Next →](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_expressions.htm "Expressions and Operators")