For further actions, you may consider blocking this person and/or reporting abuse
Read next
Mind-blowing: Why 1 == 1 is 🟢 true, but 128 == 128 is 🔴 false in Java?
Nikhil Vikraman -
Find the First Non-Repeated Character in a String
realNameHidden -
JDK, JVM, and JRE: The Three Musketeers of Java Development 🏇
Akshay Gengaje -
Arrays vs. ArrayLists: A Must-Know Topic for Java Interviews
Arshi Saxena -
Top comments (3)
Both of them refer to any chunk of code that can be reused again with different arguments and may or may not cause side effects. Traditionally called a "subroutine". They are named differently because of the different context they appear within.
A method is a subroutine that is part of the instantiation of a class (an object) in an object oriented programming language, whereas a function is a subroutine not tied to any class/object. They are also referred to as free functions sometimes.
Another thing to know from the functional programming aspect is that functions have a property that they cannot cause side effects.
Method can only be called if you have an instance of some class, whereas to call a function all you need is to provide it the required arguments it needs.
Another interpretation: a method is just a function that receives the object instance as its first argument. (Ex: the self keyword in python)
A method is a function in a object oriented context.
Function is only that, method is a function inside a class.