Know the answer? Post it. Somebody with the same question will find it here.
Thiruppathi RRank #404 · 6.2K reputationPosted Jun 28, 2016, 5:09 AM EDT
✓ Accepted answer+2
Basically 'method' and 'function' are same.Method is the correct term for a function associated with a class .but developer change their convenient method and function as in c# works that where as we mention "void" that is a method . function is a without void and return something .
Method:
public void mypgm()
{
//code
}
Function:
public string mypgm()
{
//code
return string
}
if you feel correct answer, Click accept my answer
+2
Rajeesh MenothRank #118 · 18.4K reputationPosted Jun 28, 2016, 12:00 AM EDT
+3
Hi,
Functions :
Functions have independent existence means they can be defined outside of the class. Ex:- main() function in C, C++ Language
Functions are defined in structured languages like Pascal,C and object based language like javaScript
Functions are called independently.
Functions are self describing unit of code.
Methods :
Methods do not have independent existence they are always defined with in class. Ex:- main() method in C# Language that is defined with in a class
Methods are defined in object oriented languages like C#, Java
Methods are called using instance or object.
Methods are used to manipuate instance variable of a class.
Function → Free (Free means it can be anywhere, no need to be in an object or class)
Method → Member (A member of an object or class)
Method & Function are not the same
+2
Vinay SinghRank #604 · 4K reputationPosted Jun 28, 2016, 12:36 AM EDT
+1
Hi
Function is that piece of code that has name ( called function name) and data to operate on ( called arguments) that is provided in the parenthesis adjacent to the function name. All function arguments are explicit.
Method on the other had can be viewed as a function that acts on an Object. This object is an instance of a class (blueprint of that instance). Method will always have an implicit argument as a reference to self. For example in python you use self , or in Java you use this.
So to sum it up simplistically speaking "method" is object oriented word for function .
Thiruppathi RRank #404 · 6.2K reputationPosted Jun 28, 2016, 5:09 AM EDT
Rajeesh MenothRank #118 · 18.4K reputationPosted Jun 28, 2016, 12:00 AM EDT
Lucian Patterson7 reputationPosted Jul 25, 2021, 12:06 PM EDT
Method & Function are not the same
Vinay SinghRank #604 · 4K reputationPosted Jun 28, 2016, 12:36 AM EDT
Method on the other had can be viewed as a function that acts on an Object. This object is an instance of a class (blueprint of that instance). Method will always have an implicit argument as a reference to self. For example in python you use self , or in Java you use this.
So to sum it up simplistically speaking "method" is object oriented word for function .
Daril148 reputationPosted Nov 15, 2021, 4:15 AM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts