# Apex variables, modifiers, methods and interfaces

*Platform Developer Study Guide · Process Automation and Logic · Last updated October 15, 2026 · https://www.certifyforce.com/study-guide/platform-developer/process-automation-and-logic/apex-syntax-variables-methods-interfaces*

How to declare Apex variables and static final constants, which access modifier exposes a member to whom, static versus instance members, method rules, and when to use an interface, a virtual class or an abstract class, plus what the sharing keywords declare.

- Certification: Salesforce Platform Developer
- Exam section: Process Automation and Logic
- Study guide: https://www.certifyforce.com/study-guide/platform-developer

**Official exam objective:**

> Understand how to declare variables, constants, methods, modifiers, Apex interfaces, and the appropriate use cases for each.

## What the exam expects

- Declare local and class variables, predict their initial value and scope, and declare a constant that other classes read through the class name.
- Pick the narrowest access modifier (private, protected, public, global) for a requirement, and reach a private member from a test without widening it.
- Decide between static and instance members, and predict how long a static value lives.
- Choose an interface, a virtual class or an abstract class from a design requirement, including sorting with `Comparable`.
- State what `with sharing`, `without sharing`, `inherited sharing` and an omitted declaration mean for a class.

Key terms: **constant** (a `static final` variable); **access modifier** (who can see a member); **virtual** (extendable, with overridable default bodies); **abstract** (declares bodiless methods a subclass must supply); **interface** (method signatures only, a new data type).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| Uninitialized variable | null, including Boolean (not false) and Integer (not 0) | [Variables](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_variables.htm) |
| Identifiers | Variable and method names are case-insensitive | [Variables](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_variables.htm) |
| Constant | `static final`; assigned once, in the declaration or a static block | [Constants](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_constants.htm) |
| Default member access | private | [Access Modifiers](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_access_modifiers.htm) |
| protected | Inner classes and extending classes; instance members only | [Access Modifiers](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_access_modifiers.htm) |
| global member | Its class must also be global | [Access Modifiers](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_access_modifiers.htm) |
| Static variable lifetime | One transaction; reset at the boundary | [Static and Instance](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm) |
| Method parameters | At most 32 | [Class Methods](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining_methods.htm) |
| Inheritance | Extend one class; implement many interfaces | [Apex Class Definition](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining.htm) |
| Comparable | Implement public or global `compareTo(Object)`; then `List.sort()` | [Comparable Interface](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_comparable.htm) |
| inherited sharing entry point | Runs as with sharing unless called from a without sharing context | [Sharing Keywords](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm) |

## Check yourself

- What value does `Boolean b;` hold before assignment?
- Why is a static variable safe as a recursion flag but useless as a cache?
- When should you choose a virtual class over an interface?
- Which modifier exposes a member to extending classes but not to unrelated classes?
- Why declare `with sharing` explicitly instead of omitting the keyword?

## Sources

- [Data Types and Variables](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_datatypes_variables_intro.htm)
- [Access Modifiers](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_access_modifiers.htm)
- [Interfaces](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_interfaces.htm)
- [Variables](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_variables.htm)
- [Constants](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_constants.htm)
- [Using the final Keyword](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_final.htm)
- [Static and Instance Methods, Variables, and Initialization Code](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm)
- [Class Methods](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining_methods.htm)
- [Apex Class Definition](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining.htm)
- [Extending a Class](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_extending.htm)
- [TestVisible Annotation](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_testvisible.htm)
- [Comparable Interface](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_comparable.htm)
- [Use the with sharing, without sharing, and inherited sharing Keywords](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_keywords_sharing.htm)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 9 linked practice questions, and unlimited timed mock exams are included with the Platform Developer pack (USD $19): https://www.certifyforce.com/practice-exams
