Notes
In Apex, a class variable is a variable that is declared at the class level, meaning it is a member of the class rather than being associated with a specific instance of the class. Class variables are also referred to as static variables. They are shared among all instances of a class and can be accessed using the class name rather than an instance variable.
Here's an example of how you can declare and use a class variable in Apex:
public class MyClass {
public static Integer myStaticVariable = 5;
public static Integer getMyStaticVariable() {
return myStaticVariable;
}
}
Call the Method:
System.debug(MyClass.getMyStaticVariable());
OR
Integer result = MyClass.getMyStaticVariable();
System.debug(result);
Output: 5
Video
Video does not exists.