Home > DeveloperSection > Forums > Difference between a method and a function
John Smith

Total Post:102

Posted on    July-20-2015 5:34 AM


 1 Reply(s)
 867  View(s)
Rate this:
Hi Everyone,
What is the difference between method and function?
Can someone provide a simple explanation of methods and functions?

Good for the beginners.


Mayank Tripathi
Mayank Tripathi

Total Post:397

Posted on    July-20-2015 8:31 AM

A function is a piece of code that is called by name. It can be passed data to operate on (ie. the parameters) and can optionally return data (the return value).

All data that is passed to a function is explicitly passed.

A method is a piece of code that is called by name that is associated with an object. In most respects it is identical to a function except for two key differences.

It is implicitly passed for the object for which it was called.
It is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data).

Don't want to miss updates? Please click the below button!

Follow MindStick