Functions vs Methods

Difference between Functions and Methods

S.No Functions Methods
Functions do not have any reference variables
Methods are called by reference variables
All data that is passed to a function is explicitly passed
It is implicitly passed the object for which it was called
3 It does not have access controlling i.e.,Function(other than static functions) declares and defines anywhere in the code
It has access controlling i.e.,Method should declare and define in the class only

4 Function applies to both object oriented and non-object oriented language(procedural language.eg. C, Scripting language eg; JavaScript etc) Method is only applicable to object oriented programming language like C++, C#, Java etc

A function is just a part of code that executes code and can return something.
A method is, in OOP, a function that is bound to a class. As in C# there are no stand-alone functions, every function in C# is a method

No comments:

Post a Comment