+ 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?

5th Dec 2017, 3:41 AM
Curt Griffin
Curt Griffin - avatar
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.
5th Dec 2017, 3:52 AM
Fox
Fox - avatar
+ 4
functions are their own sets of gears. methods are the gears grouped into a class
5th Dec 2017, 3:56 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 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)
5th Dec 2017, 5:52 AM
#RahulVerma
#RahulVerma - avatar
+ 3
Perfect answers. Thanks guys!
5th Dec 2017, 4:03 AM
Curt Griffin
Curt Griffin - avatar
+ 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.
6th Dec 2017, 1:35 AM
Red Hawks
Red Hawks - avatar
+ 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.
5th Dec 2017, 4:05 AM
1of3
1of3 - avatar