+ 5
What is the difference between a function and a method?
Is there a fundamental difference between the two concepts or are they the same thing with a different name?
6 Answers
+ 7
You will find that functions and methods are known by a couple of different names in other languages.
Basically, functions are exactly how the SoloLearn courses explain them. The difference when it comes to methods, is that a 'method' is a function, except that it's defined within a class, rather than the main body of the program.
+ 4
functions are their own sets of gears.
methods are the gears grouped into a class
+ 4
Method uses the 'dot' notation
// A function
x = function()
// A method
this.x = function()
You will learn more about method and functions in Object Oriented Programming (OOP)
+ 3
Perfect answers. Thanks guys!
+ 2
method = function declared in a class
That's why in Java we refer to all functions as methods because in Java everything is declared and implemented inside a class and everything is an object.
+ 1
A function with x parameters is equivalent to a method with x-1 parameters.
Like, some languages do
length(string) / function with 1 parameter
and some
string.length() / method with 0 parameters
That is because the owner is always known to the method.