Skip to content

Latest commit

 

History

History
25 lines (23 loc) · 429 Bytes

static_methods.md

File metadata and controls

25 lines (23 loc) · 429 Bytes

Static Methods

If you want to be able to call a method from anywhere in your program you can use a static method.

class MyMath {
    static int add(int a, int b) {
        return a + b;
    }
}
~class MyMath {
~    static int add(int a, int b) {
~        return a + b;
~    }
~}
class Main {
    void main() {
        int result = MyMath.add(1, 2);
        System.out.println(result);
    }
}