Difference Between Function and Method
Function: A Function is a reusable piece of code. It can have input data on which it can operate (i.e. arguments) and it can also return data by having a return type. It is the concept of procedural and functional programming languages.
Method: The working of the method is similar to a function i.e. it also can have input parameters/arguments and can also return data by having a return type but has two important differences when compared to a function.
- A method is associated or related to the instance of the object it is called using.
- A method is limited to operating on data inside the class in which the method is contained.
- It is a concept of object-oriented programming language.
In simple words if a function is part of an instance of a class i.e. (Object) then it is called method else it is called function.
|It is called by its own name/independently.||It is called by its object’s name/referenced.|
|As it is called independently it means the data is passed explicitly or externally.||As it is called dependently which means the data is passed implicitly or internally.|
Implementation of Function in Procedural Programming Language(C):
Implementation of Function in Object Oriented Programming Language(JAVA):