All Products
Search
Document Center

OpenSearch:Modifiers

Last Updated:Sep 09, 2021

static

The static modifier is used to define class functions. For more information, see Classes and objects. Note: Cava allows you to define member variables but not class variables. If you use the static modifier to define a class variable, as shown in the following sample code, an error occurs during compilation:

class Example {
    static int i; // An error occurs during complication.
    static int main() {
        return 0;
    }
}
ERROR cava.common.Diagnostics : benchmark/example.cava:1.15-2.16 [30001] static variable is not support:i

Access modifiers

Cava is syntactically compatible with the following access modifiers:

  • public

  • protected

  • private

  • final

However, access modifiers do not affect the access to a class member. No matter which access modifier you use for the class member, the class member is publicly accessible.

class Example {
    public double PI; // <==
    Example() {
        PI = 3.1415926;
    }
    static int main() {
        Example example = new Example();
        double a = example.PI;
        return 0;
    }
}

To avoid confusion, we recommend that you do not use access modifiers in Cava.