In object-oriented programming a method is a function associated with a particular class or object. In most forms of object oriented implementations methods can be static, associated with the class itself; or instance, associated with an instance of a class.

Show how to call a static or class method, and an instance method of a class.

struct Cat {
    static int staticMethod() {
        return 2;
    }
 
    string dynamicMethod() { // Never virtual.
        return "Mew!";
    }
}
 
class Dog {
    static int staticMethod() {
        return 5;
    }
 
    string dynamicMethod() { // Virtual method.
        return "Woof!";
    }
}
 
void main() {
    // Static methods calls:
    assert(Cat.staticMethod() == 2);
    assert(Dog.staticMethod() == 5);
 
    Cat c; // This is a value on the stack.
    Dog d; // This is just a reference, set to null.
 
    // Other static method calls, discouraged:
    assert(c.staticMethod() == 2);
    assert(d.staticMethod() == 5);
 
    // Instance method calls:
    assert(c.dynamicMethod() == "Mew!");
    d = new Dog;
    assert(d.dynamicMethod() == "Woof!");
}