The words are not opposed to each other but rather describes two possible aspects of a subroutine. An attempt to define the words follows:
Subroutine: A set of instructions that can be used several times in the same program.
Function: A subroutine that returns a value. Derived from functions in mathematics.
Method: A subroutine that belongs to an object or a class. Could be a function.
Subroutine: A set of instructions that can be used several times in the same program.
Function: A subroutine that returns a value. Derived from functions in mathematics.
Method: A subroutine that belongs to an object or a class. Could be a function.
Method is actually a function used in the context of a class/object. When you create a function outside of a class/object, you can call it a function but when you create a function inside a class, you can call it a method.
So an object can have methods (functions) and properties (variables). Source : Stackoverflow |
Comments
Post a Comment