Difference between method and function?

Asked

Viewed 274 times

1

Because in Java it’s called method and in Kotlin it’s called function, it’s just a different nomenclature, or is there a significant difference?

Java:

public class Teste {
    public static void main(String[] args) {
        int result = multiplicaDois(2);      
        System.out.print(result);
    }

    public static int multiplicaDois(int x) {
        return 2 * x; 
    }
}


Kotlin:

fun main(args: Array<String>) {
    val result = multiplicaDois(2);
    println(result);    
}

fun multiplicaDois(x: Int): Int {
    return 2 * x;
}
  • 3

    Related: https://answall.com/q/11848/57801

  • Basically there is no difference, in the past this difference in theory existed. The default is that the functions that exist within a class have the method name, because they are methods that are executed by the class. It’s more like defining languages that use object orientation.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.