Are Functions called Methods in Java

Question from Em.#0694


Are functions called methods in Java?

Yes, but the caveat is that you don't have true "free standing" functions.

so in python

def f(x, y):
    return x + y

This is a function, it is its own thing. In Java "methods" have to "belong" to something either instances of a class or to the class itself.



that makes sense

class Thing {
    static int f(int x, int y) {
        return x + y;

so this f function in python, translated to java has to "belong" to some class as a "static method".

<- Index