Home » Difference Between » Function and Method

What is Difference between Method and Function?

Function and Methods are two different concepts used in the programming language. The main difference between these two terms is that the function is defined in the Structured Language while Methods are defined in the Object Oriented Language

Function V/S Method

FunctionMethod
Functions can be declared outside the class environment.Methods are declared within the class
Functions are mainly defined in structured language like C, Pascal etcMethods are defined in the Object Oriented Programming Language like Jave, C#
Functions in any programming language are called independently.Methods in object oriented programming language are called using the Object of Class
Example:
void main()
{
int x,y,z;
x=10;
y=20;
z=x+y;
printf("Sum is : %d",z);
}
Example:
class example
{
int x,y,z;
public void sum()
{
x=5;
y=6;
z=x+y;
Console.WriteLine("Sum is : {0}",z);
}
}

Conclusion:

In this difference between sections I have explained the difference between Method and function used in programming language. Hope the above mentioned differences are helpful for you. In case if you need further information on that topic or has any query then start the discussion by commenting below. I would love to assist you.